Django Unit Testing in VSCode
You can find information about debugging Django using VSCode here. The extension does not have builtin support for Django UnitTests, but we can use pytest to run Django UnitTests. Please make sure that you have installed pytest and pytest-django. They can be installed using pip.
pip install pytest
pip install pytest-django
Go to Default Settings and search for ‘python.unitTest’. Change the setting
Create a file called ‘pytest.ini’ in your work space root and add the following content to that file. Remember to change the myproject.settings to your actual settings module.
DJANGO_SETTINGS_MODULE = myproject.settings
Well, That’s all the settings required to run django unit tests. Click the ‘Run Tests’ button on the status bar and select ‘Run All Unit Tests’ from the context menu.
Tests will run and the result summary will be displayed on the output tab. If the test output is not visible, select ‘Run Tests’ and select ‘View Unit Test Output’. Summary of the tests can be viewed from the status bar as well.