I am setting up a Python project in VisualStudio Code. My folder and file structure looks like follows:
- Base project folder
- source_folder
- package1_folder
- module1.py
- package2_folder
- module2.py
- package1_folder
- source_folder_unittests
- package1_unittests
- module1_test.py
- package1_unittests
- source_folder
Sadly, the unittest discovery does not see the unit tests inside 'module_test.py'. As soon as I move the module1_test.py file one folder up, it works:
- Base project folder
- source_folder
- package1_folder
- module1.py
- package2_folder
- module2.py
- package1_folder
- source_folder_unittests
- module1_test.py
- source_folder
This is my settings.json file:
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./source_folder_unittests/",
"-p",
"*_test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
}
Does VS Code not recognize unit tests in subfolders? Or am I missing something I have to do? I already added the source_folder to the PYTHONPATH environment variable.
__init__.pyin every folder on your project. I'm not sure this is the cause, but it is worth a try.