Reputation: 17525
There are lots of similar questions (e.g. 1, 2, 3, 4, 5, 6, …) but none have quite this combination of issues (i.e. the unittest discovery working at the shell prompt), and the solutions to those questions have not worked for me.
When I run Python: Discover Tests
in Visual Studio Code I get the error
No tests discovered, please check the configuration settings for the tests.
My settings.json file looks like this
{
"python.testing.unittestArgs": [
"--verbose",
"--start-directory",
"./preprocessing/",
"--pattern",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
But I know the unittests are discoverable, because if I run this command from the root of my project all the tests are discovered and run:
python -m unittest discover --verbose --start-directory "./preprocessing/" --pattern "test_*.py"
My tests clearly are discoverable by Python's unittest framework, but VS Code does not find them. How might I fix this?
Upvotes: 5
Views: 3722
Reputation: 21
I struggled with this as well for a while. My solution was to rename the class to Test_MyTest(unittest.TestCase)
instead of just TestMyTest(unittest.TestCase
. This matches the "test_*.py" file name that I configured in VSCode but I don't know if the file name and class name need to match.
Upvotes: 0
Reputation: 2122
You'll need to set the PYTHONPATH in the .env file in the root directory of your project. Make sure that all directories containing src files and tests are on the pythonpath. For details see here.
Upvotes: 1
Reputation: 16080
I would try running without --verbose
. It's not necessary since the extension is doing the discovering for you, plus I bet the extra output from it is breaking something.
Upvotes: 0