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
Test suite discovery error on imports that use shared filenames with the pythonFiles>unittestadapter directory #22453
Due to PATH ordering, shared directory/file names in a users codebase with the pythonFiles > unittestadapter directory will fail.
Error: ModuleNotFoundError: No module named 'utils.<name>; 'utils' is not a package
Problem:
When running the test suite, we run discovery.py which adds unittestadapter to path at index 0.
In some tests that import a file from utils, it will first search within the unittestadapter directory due to PATH ordering
The discovery will now fail because it detects utils as a file and not a module since its reading the utils.py file from the unittestadapter directory.
Solution:
Once starting to run discovery, add the projects root path to PATH at index 0 so that any further imports will use the projects root directory and not reference the incorrect directory.
Since the test suite only allows the start_dir to be one directory deep, we can conclude that if the start_dir is not "." or contains a "/", that we need to add that start_dir's parent to PATH. Otherwise, we simply add the start_dir to PATH.
This worked for me after I ran python3 -m pip install pytest, reloaded the window, and reran test discovery, selecting unittest as the test framework. Why does unittest test discovery depend on pytest, and can we help the user out with installing the package?
Activity
eleanorjboyd commentedon Nov 27, 2023
thanks again for contributing to the repo and putting in this fix!
Resolve test suite discovery import errors due to path ordering (micr…
eleanorjboyd commentedon Nov 27, 2023
should be able to verify with the following set up:
project structure with
my_utilscontainingsome_functiontest which should now work:
made a zip of a project that should replicate this:
my_project.zip
bhavyaus commentedon Nov 29, 2023
Eleanor Boyd (@eleanorjboyd) I'm still seeing the import error mentioned in the description:
I might be missing a few setup steps but would like to learn.
joyceerhl commentedon Nov 29, 2023
This worked for me after I ran

python3 -m pip install pytest, reloaded the window, and reran test discovery, selecting unittest as the test framework. Why does unittest test discovery depend on pytest, and can we help the user out with installing the package?eleanorjboyd commentedon Nov 29, 2023
What do you have as your settings for your unittest args?