Skip to content

Commit

Permalink
Resolve test suite discovery import errors due to path ordering (#22454)
Browse files Browse the repository at this point in the history
[Issue #22453](#22453)

- 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.
  • Loading branch information
shanesaravia authored Nov 27, 2023
1 parent eb96141 commit 9a5363c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pythonFiles/unittestadapter/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def discover_tests(
}
"""
cwd = os.path.abspath(start_dir)
if "/" in start_dir: # is a subdir
parent_dir = os.path.dirname(start_dir)
sys.path.insert(0, parent_dir)
else:
sys.path.insert(0, cwd)
payload: PayloadDict = {"cwd": cwd, "status": "success", "tests": None}
tests = None
error: List[str] = []
Expand Down

0 comments on commit 9a5363c

Please sign in to comment.