Unit Tests Not Discovered In Python - Visual Studio Code

青春壹個敷衍的年華 提交于 2021-01-28 01:40:23

问题


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:

  1. I did not have ____init__.py in my subdirectories.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!