Just learned if you add "django": true to your config, you can debug the django HTML templates! See -> code.visualstudio.com/docs/python/debugging under 'Specific app types" You might also want to add these two lines of code to the end of your test file so you can re-run the test after hitting a breakpoint. if __name__ == "__main__": unittest.main()
I'm currently using the same setup, but I find it really confusing as manage.py test will leverage a test database while setting up like this will use the production database. Any idea how to configure it to use the test database? Trying out but no luck so far
I also had this same issue. The workaround I came up with is to check for keywords in sys.argv to find out what has started the Django instance. If it's pytest, I switch the database out. import sys found_count = len( {item for item in ["pytest"] if any(item in arg for arg in sys.argv)} ) if found_count > 0: DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "db.sqlite3"), } } You can see my whole settings.py here github.com/jsolly/blogthedata/blob/master/django_project/django_project/settings.py
@@johnsolly Thanks for the info! I'm using unittest so I did figure out a workaround solution. I created another settings.py file and ask all vscode tests routing to the test database. I find that the setup only works for vscode, so this is what I end up doing at least for now.
@@xuelinli3813 I recently did the same. I'm using two postgres databases. One for testing, one for development. You can see how I split up my settings files here github.com/jsolly/blogthedata/tree/master/django_project/django_project/settings
I m getting: Subprocess exited unsuccessfully with exit code 1 and signal null on workspace. path/to/my/project/ Creating and sending error discovery payload. pytest test discovery error for workspace: The python test process was terminated before it could exit on its own, the process errored with: Code: 1, Signal: null for workspace path/to/my/project/
Hey, I tried a lot. So after doing everything as he mentioned in the video, just restart your vs code. Even if that doesn’t work, try to reboot. That might solve the problem
This was very helpful, thanks. I couldn't figure out how to do it.
Thanks, but this is quite inconvenient to write those setup() in every test file
I agree, If you find a better way, let me know!
great thanks!
Just learned if you add "django": true to your config, you can debug the django HTML templates! See -> code.visualstudio.com/docs/python/debugging under 'Specific app types"
You might also want to add these two lines of code to the end of your test file so you can re-run the test after hitting a breakpoint.
if __name__ == "__main__":
unittest.main()
I'm currently using the same setup, but I find it really confusing as manage.py test will leverage a test database while setting up like this will use the production database. Any idea how to configure it to use the test database? Trying out but no luck so far
I also had this same issue. The workaround I came up with is to check for keywords in sys.argv to find out what has started the Django instance. If it's pytest, I switch the database out.
import sys
found_count = len(
{item for item in ["pytest"] if any(item in arg for arg in sys.argv)}
)
if found_count > 0:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
You can see my whole settings.py here
github.com/jsolly/blogthedata/blob/master/django_project/django_project/settings.py
@@johnsolly Thanks for the info! I'm using unittest so I did figure out a workaround solution. I created another settings.py file and ask all vscode tests routing to the test database. I find that the setup only works for vscode, so this is what I end up doing at least for now.
@@xuelinli3813 I recently did the same. I'm using two postgres databases. One for testing, one for development. You can see how I split up my settings files here
github.com/jsolly/blogthedata/tree/master/django_project/django_project/settings
I m getting: Subprocess exited unsuccessfully with exit code 1 and signal null on workspace. path/to/my/project/ Creating and sending error discovery payload. pytest test discovery error for workspace: The python test process was terminated before it could exit on its own, the process errored with: Code: 1, Signal: null for workspace path/to/my/project/
same issue here
Hey, I tried a lot. So after doing everything as he mentioned in the video, just restart your vs code. Even if that doesn’t work, try to reboot.
That might solve the problem