问题
I am using visual studio code to program in python and I am attempting to run unittests but my test files are not being discovered. I am getting the following message:
"No tests discovered, please check the configuration settings for the tests."
My script (problem1.py) and my test script (problem1_test.py) are in the same directory. My settings are configured as follows:
{
"python.pythonPath": "C:\\Users\\Adam\\AppData\\Local\\Programs\\Python\\Python36\\python.exe",
"python.unitTest.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*test.py"
],
"python.unitTest.unittestEnabled": true,
"python.unitTest.pyTestEnabled": false,
"python.unitTest.nosetestsEnabled": false,
"python.unitTest.promptToConfigure": false
}
Not sure if I am missing something, any help would be appreciated.
回答1:
I have a solution that may not solve your problem but it fixed mine. There were two issues:
- I did not have ____init__.py in my subdirectories.
- My derived test class had a function definition error.
The definition for my derived unit test class had an error. In my case, I had an init function with the wrong parameters. When VS tries to find the unit tests it calls "C:\Python36\lib\unittest\loader.py" which ultimately gave me this error when parsing my files:
TypeError: __init__() takes 1 positional argument but 2 were given
I could see this in the OUTPUT window tab at the bottom of VS Code. When I fixed my test case syntax it found tests.
来源:https://stackoverflow.com/questions/48364021/unit-tests-not-discovered-in-python-visual-studio-code