I am trying to run Django unit tests in the VSCode Test Explorer, also, I want the CodeLens 'Run Tests' button to appear above each test. enter image description here However, in the Test Explorer, When I press the Play button, an error displays: "No Tests were Ran" No Tests were Ran
My directory structure is:
I am using the unittest framework. My Settings.json looks like this:
{
"python.pythonPath": "/Users/nbonilla/.local/share/virtualenvs/koku-iTLe243o/bin/python",
"python.testing.unittestArgs": [
"-v",
"-s",
"${workspaceFolder}/python_module_1/sub_module/"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true,
}
When I press the green "Play" button Test Explorer Play Button The Python Test Log Output shows the message "Unhandled exception in thread started by" Unhandled Exception in thread started by I am using a pipenv virtual environment. How do I run these Django Tests in the VSCode Test Explorer?
I saw that using pyTest is an alternative to unittest, how can this be set up easily as a replacement?
You can create a customized launch profile in VS Code, which is also used for the inevitable exercise of debugging. Select the link and VS Code will prompt for a debug configuration. Select Django from the dropdown and VS Code will populate a new launch. json file with a Django run configuration.
Open /catalog/tests/test_models.py.TestCase , as shown: from django. test import TestCase # Create your tests here. Often you will add a test class for each model/view/form you want to test, with individual methods for testing specific functionality.
Open a Python project. Once the project is loaded in Visual Studio, right-click your project in Solution Explorer and select the unittest or pytest framework from the Properties Test tab. If you use the pytest framework, you can specify test location and filename patterns using the standard pytest .
Please consider the following checks:
1- you should have __init__.py in your test directory
2- in vscode on test configuration use pytest framework
3- use: pip install pytest-django
4- copy pytest.ini in the root with this content:
# -- FILE: pytest.ini (or tox.ini)
[pytest]
DJANGO_SETTINGS_MODULE = <your-web-project-name>.settings (like mysite.settings)
# -- recommended but optional:
python_files = tests.py test_*.py *_tests.py
Now it should work as you wish. you can see this stackoverflow link :
https://stackoverflow.com/questions/55837922/vscode-pytest-test-discovery-fails
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With