Skip to content

Commit

Permalink
Add parent directory to sys.path for unittest discovery and execution (
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd authored Jun 27, 2024
1 parent 62ded1f commit bd6a924
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python_files/unittestadapter/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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: DiscoveryPayloadDict = {"cwd": cwd, "status": "success", "tests": None}
tests = None
error: List[str] = []
Expand Down
5 changes: 5 additions & 0 deletions python_files/unittestadapter/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def run_tests(
locals: Optional[bool] = None,
) -> ExecutionPayloadDict:
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)
status = TestExecutionStatus.error
error = None
payload: ExecutionPayloadDict = {"cwd": cwd, "status": status, "result": None}
Expand Down

0 comments on commit bd6a924

Please sign in to comment.