Skip to content

Commit 9a5363c

Browse files
authored
Resolve test suite discovery import errors due to path ordering (#22454)
[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.
1 parent eb96141 commit 9a5363c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pythonFiles/unittestadapter/discovery.py

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def discover_tests(
7373
}
7474
"""
7575
cwd = os.path.abspath(start_dir)
76+
if "/" in start_dir: # is a subdir
77+
parent_dir = os.path.dirname(start_dir)
78+
sys.path.insert(0, parent_dir)
79+
else:
80+
sys.path.insert(0, cwd)
7681
payload: PayloadDict = {"cwd": cwd, "status": "success", "tests": None}
7782
tests = None
7883
error: List[str] = []

0 commit comments

Comments
 (0)