question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError and can't run/debug unittest

See original GitHub issue

Environment data

  • VS Code version: 1.60.0
  • Extension version (available under the Extensions sidebar): 2021.9.1218897484
  • OS and version: MacOS Mojave 10.14.6 (in a Codespace)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.6 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): pipenv --global
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Value of the python.languageServer setting: not set

Expected behaviour

unittest tests are automatically detected and show up in testing side bar"

Screen Shot 2021-09-09 at 19 25 42

Actual behaviour

They do not, and I get:

Screen Shot 2021-09-09 at 19 21 59

Steps to reproduce:

While working on https://github.com/JEFuller/dataclasses-configobj

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'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
LoicHcommented, 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 install to have your requirements to run your tests 😉

1reaction
karthiknadigcommented, Sep 30, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IntelliJ Python unittests cannot import modules - Stack Overflow
My final solution is to add the classpath of the module to Run/Debug Configurations: Open Run/Debug Configurations and select your unittest ...
Read more >
PyCharm - Run/Debug Configuration: Python Unit Test
You can type in the module name, search the target module by its name, or locate it in the project structure.
Read more >
python unittest module not found - You.com | The AI Search ...
Python Unit test module throws "ModuleNotFoundError: No module named ... _accounts: raise ValueError ('Accounts cannot be assigned to the same Market ...
Read more >
Set up unit testing for Python code - Visual Studio
Setting up unit testing for Python code in Visual Studio takes full advantage of Test Explorer features to discover, run, and debug tests....
Read more >
Developing Python Web Applications with Flask
Flask does not provide an integrated Model (M) layer, and lets you pick ... in your Eclipse PyDev (to avoid the annoying module...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found