From a4a6cd1c64ac357b656038cfb4ca47560898776a Mon Sep 17 00:00:00 2001 From: Shane Saravia Date: Fri, 29 Mar 2024 14:24:07 -0500 Subject: [PATCH] Resolve test suite execution import errors due to path ordering (microsoft/vscode-python#23099) - This has already been discussed and resolved for tests discovery in this [PR](https://github.com/microsoft/vscode-python/pull/22454) - I have now run into the same issue for executing the test suite and have applied the same fix in this PR - Tested and working [Issue](https://github.com/microsoft/vscode-python/issues/23098) for this current PR [Original Issue](https://github.com/microsoft/vscode-python/issues/22453) [Original PR](https://github.com/microsoft/vscode-python/pull/22454) Co-authored-by: Eleanor Boyd --- .../python_files/unittestadapter/execution.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/positron-python/python_files/unittestadapter/execution.py b/extensions/positron-python/python_files/unittestadapter/execution.py index 9394303b69a..6b925290647 100644 --- a/extensions/positron-python/python_files/unittestadapter/execution.py +++ b/extensions/positron-python/python_files/unittestadapter/execution.py @@ -171,6 +171,11 @@ def run_tests( locals: Optional[bool] = None, ) -> PayloadDict: 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: PayloadDict = {"cwd": cwd, "status": status, "result": None}