From 4b980fdb2438b88e7b454e0108c62988e4cd74cf Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Mon, 13 May 2024 10:55:44 -0700 Subject: [PATCH] add sys config scripts path to test execution path --- python_files/unittestadapter/execution.py | 8 ++++++++ python_files/vscode_pytest/run_pytest_script.py | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python_files/unittestadapter/execution.py b/python_files/unittestadapter/execution.py index bcac2779887e..5645241fb651 100644 --- a/python_files/unittestadapter/execution.py +++ b/python_files/unittestadapter/execution.py @@ -9,10 +9,18 @@ import socket import sys import traceback +import sysconfig import unittest from types import TracebackType from typing import Dict, List, Optional, Tuple, Type, Union +# Adds the scripts directory to the PATH as a workaround for enabling shell for test execution. +path_var_name = "PATH" if "PATH" in os.environ else "Path" +os.environ[path_var_name] = ( + sysconfig.get_paths()["scripts"] + os.pathsep + os.environ[path_var_name] +) + + script_dir = pathlib.Path(__file__).parent.parent sys.path.append(os.fspath(script_dir)) sys.path.insert(0, os.fspath(script_dir / "lib" / "python")) diff --git a/python_files/vscode_pytest/run_pytest_script.py b/python_files/vscode_pytest/run_pytest_script.py index cdf996e29ba2..fae9b5e4af18 100644 --- a/python_files/vscode_pytest/run_pytest_script.py +++ b/python_files/vscode_pytest/run_pytest_script.py @@ -5,9 +5,15 @@ import pathlib import socket import sys - +import sysconfig import pytest +# Adds the scripts directory to the PATH as a workaround for enabling shell for test execution. +path_var_name = "PATH" if "PATH" in os.environ else "Path" +os.environ[path_var_name] = ( + sysconfig.get_paths()["scripts"] + os.pathsep + os.environ[path_var_name] +) + script_dir = pathlib.Path(__file__).parent.parent sys.path.append(os.fspath(script_dir)) sys.path.append(os.fspath(script_dir / "lib" / "python"))