This is with Python Language Server version 0.3.43.0 on Windows 10, Anaconda python 3.7.3.
Have a folder with the following structure:
mypkg
--> foo.py
--> __init__.py
mypkg_test
--> __init__.py
--> base.py
--> test_foo.py
The files base.py, and both __init__.py are empty.
Here is foo.py:
Here is test_foo.py:
import unittest
from . import base
from mypkg.foo import goo
class FooTest2(unittest.TestCase):
def test_foo(self):
x = goo()
self.assertTrue(5 == x)
if __name__ == '__main__':
unittest.main()
Here is settings.json in the .vscode folder in that directory:
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./mypkg_test",
"-p",
"test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
If you comment out from . import base in test_foo.py, then the test is discovered. Commenting and uncommenting that line makes the test discovered versus not discovered, as evidenced by seeing the buttons Run Test|Debug Test in the editor.
If you rename mypkg_test to test, update the test settings to point to the newly named directory, and leave the source with the line from . import base present, then the test is discovered.
So the name of the test folder seems to affect test discovery when doing a relative import inside one of the tests.
We have a big source code with this naming structure (and I don't control the naming) and base.py has a lot more stuff in it, and we can run tests just fine from the command line, but not from VS Code.
This is with Python Language Server version 0.3.43.0 on Windows 10, Anaconda python 3.7.3.
Have a folder with the following structure:
The files
base.py, and both__init__.pyare empty.Here is
foo.py:Here is
test_foo.py:Here is
settings.jsonin the.vscodefolder in that directory:{ "python.testing.unittestArgs": [ "-v", "-s", "./mypkg_test", "-p", "test*.py" ], "python.testing.pytestEnabled": false, "python.testing.nosetestsEnabled": false, "python.testing.unittestEnabled": true }If you comment out
from . import baseintest_foo.py, then the test is discovered. Commenting and uncommenting that line makes the test discovered versus not discovered, as evidenced by seeing the buttonsRun Test|Debug Testin the editor.If you rename
mypkg_testtotest, update the test settings to point to the newly named directory, and leave the source with the linefrom . import basepresent, then the test is discovered.So the name of the test folder seems to affect test discovery when doing a relative import inside one of the tests.
We have a big source code with this naming structure (and I don't control the naming) and
base.pyhas a lot more stuff in it, and we can run tests just fine from the command line, but not from VS Code.