Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Test suite discovery error on imports that use shared filenames with the pythonFiles>unittestadapter directory #22453

Copy link
Copy link
Closed
@shanesaravia

Description

@shanesaravia
Issue body actions

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.