ModuleNotFoundError when running tests from subfolders
See original GitHub issueDescribe the bug
Running unittest
tests from project subfolders is very fragile. It’s common to receive the error "ModuleNotFoundError: No module named ‘[your test module]’ when executing.
The following seems to work:
- Test modules in the root of the project
- Test modules in a subfolder, with the same name as the subfolder
Everything else fails.
Steps to Reproduce
- Unzip TestErrors.zip and try to execute tests.
Expected behavior Test methods are executed.
Additional context and screenshots
Failed to import test module: tests_foo
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\unittest\loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
ModuleNotFoundError: No module named 'tests_foo'
Sample Code TestErrors.zip
Diagnostics file Diagnostic Info 2020-03-21T162604.txt
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
unit testing - Run all tests from subdirectories in Python
A good approach is to run all the tests in a subdirectory from the command line. In order to find the following files...
Read more >Good Integration Practices
Your tests can run against an installed version after executing pip install . . Your tests can run against the local copy with...
Read more >Modules from specified sub-folders not recognized/loaded
is fully recognized by autocomplete. When I run it, I get the following: No module named folder1.module1.
Read more >Python VSCode not seeing tests in subfolder
I've broken up my Python project into 2 modules, each one with its own folder. Each folder contains a file for unit tests...
Read more >İmport a python function inside a subfolder
It still says ModuleNotFoundError: No module named 'my_functions' ... I am running test.py from the myProjects folder using python test.py .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To my experience the problem still exist. __init__py -pp ----init.py ----person.py -test_pp ----__init__py ----test_person.py
from pp.person import Person
throws Error:did you fix/workaround this?