Skip to content

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

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions