You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ModuleNotFoundError and can't run/debug unittest #17363
Running on 2021.9.1191016588 is ✅
but updating to 2021.9.1218897484 is ❌
I can switch between versions and the tests appear and disappear, as show above ⬆️
Logs
Output for Python in the Output panel >
/usr/bin/python3 ~/.vscode-remote/extensions/ms-python.python-2021.9.1218897484/pythonFiles/testing_tools/unittest_discovery.py ./tests test_*.py
cwd: /workspaces/dataclasses-configobj
Error 2021-09-10 02:00:49: Error discovering unittest tests:
Failed to import test module: test_core
Traceback (most recent call last):
File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/workspaces/dataclasses-configobj/tests/test_core.py", line 7, in <module>
from dataclasses_configobj import core
ModuleNotFoundError: No module named 'dataclasses_configobj'
Looks like the issue is with PYTHONPATH. essentially when we were running discovery using '-c' Python would add [''] to the front of sys.path, this meant that the CWD would be looked at while import resolution. But when we switched to using a script, it does not add [''], which cause the module not found error.
Brett Cannon (@brettcannon) What do you recommend we do here? insert '' to sys.path in the unittest discovery script, OR is there a better way?
Youngbeom Choi (@helloybz) Can you make sure that you are using latest python extension version: 2021.9.1218897484?
With the settings you mentioned above I am seeing this, I don't see it missing the .:
Hey Karthik Nadig (@karthiknadig) was there a resolution for this? I'm having the exact same issue, latest Python extension installed v2021.9.1246542782
This particular issue is fixed. If you are seeing ModuleNotFoundError it can be for a variety of reasons. Please file a separate bug with details so we can investigate.
I was having the same issue, stumbled upon this page, and for those who still have the same problem: don't forget to run pip install to have your requirements to run your tests 😉
I still have this issue with 2021.9.1246542782. Manually, I can run the command that VS Code seems to execute, python ~/.vscode-server/extensions/ms-python.python-2021.9.1246542782/pythonFiles/testing_tools/unittest_discovery.py ./tests test_*.py inside my venv just fine, but VS Code does not find the tests.
Activity
hogegex commentedon Sep 10, 2021
I have the same problem.
It seems that the directories inside the workspace folder are not recognized as packages.
(PYTHONPATH problem?)
If write "import my_pkg" to
test_foo.pyof the following files, the test will not be detected.If remove it, the test will be detected.
karthiknadig commentedon Sep 10, 2021
Looks like the issue is with PYTHONPATH. essentially when we were running discovery using '-c' Python would add [''] to the front of
sys.path, this meant that the CWD would be looked at while import resolution. But when we switched to using a script, it does not add [''], which cause the module not found error.Brett Cannon (@brettcannon) What do you recommend we do here? insert '' to
sys.pathin the unittest discovery script, OR is there a better way?helloybz commentedon Sep 10, 2021
I have the same problem.
Below is my
unittestconfigures in.vscode/setting.json.{ "python.testing.unittestArgs": [ "-v", "-s", "./tests", "-p", "test_*.py" ] }And I've found that the
start-directory"./test" becomes "/test" in discover::unittest.loader.TestLoaderAny idea about why the "./test" becomes "/test"??
karthiknadig commentedon Sep 10, 2021
Youngbeom Choi (@helloybz) Can you make sure that you are using latest python extension version:

2021.9.1218897484?With the settings you mentioned above I am seeing this, I don't see it missing the
.:brettcannon commentedon Sep 10, 2021
The cwd should still be the first entry in
sys.pathregardless of whether-mor-cwas used.karthiknadig commentedon Sep 10, 2021
This is using script, so no
-mor-c.tonycassara commentedon Sep 30, 2021
Hey Karthik Nadig (@karthiknadig) was there a resolution for this? I'm having the exact same issue, latest Python extension installed
v2021.9.1246542782karthiknadig commentedon Sep 30, 2021
This particular issue is fixed. If you are seeing
ModuleNotFoundErrorit can be for a variety of reasons. Please file a separate bug with details so we can investigate.LoicH commentedon Oct 5, 2021
I was having the same issue, stumbled upon this page, and for those who still have the same problem: don't forget to run
pip installto have your requirements to run your tests 😉dlencer commentedon Oct 7, 2021
I still have this issue with
2021.9.1246542782. Manually, I can run the command that VS Code seems to execute,python ~/.vscode-server/extensions/ms-python.python-2021.9.1246542782/pythonFiles/testing_tools/unittest_discovery.py ./tests test_*.pyinside myvenvjust fine, but VS Code does not find the tests.dlencer commentedon Oct 8, 2021
With today's update (VS Code 1.61, Python Extension v2021.10.1317843341), test discovery is working again. Thanks!