2

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.

  • Just to clarify, are you using Visual Studio test environment for this, or any other testing framework? https://learn.microsoft.com/en-us/visualstudio/python/unit-testing – pastaleg Jan 21 '18 at 05:43

1 Answers1

0

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.

ChuckZ
  • 330
  • 3
  • 13