From f0cb542acdec41f9c1a4e9e70bae207836b67b0d Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Thu, 18 Dec 2025 11:30:37 -0800 Subject: [PATCH] fix(execution): redirect error messages to stderr and clean up print statements --- python_files/unittestadapter/execution.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/python_files/unittestadapter/execution.py b/python_files/unittestadapter/execution.py index a0a48c61470a..951289850884 100644 --- a/python_files/unittestadapter/execution.py +++ b/python_files/unittestadapter/execution.py @@ -284,10 +284,10 @@ def send_run_data(raw_data, test_run_pipe): run_test_ids_pipe = os.environ.get("RUN_TEST_IDS_PIPE") test_run_pipe = os.getenv("TEST_RUN_PIPE") if not run_test_ids_pipe: - print("Error[vscode-unittest]: RUN_TEST_IDS_PIPE env var is not set.") + print("Error[vscode-unittest]: RUN_TEST_IDS_PIPE env var is not set.", file=sys.stderr) raise VSCodeUnittestError("Error[vscode-unittest]: RUN_TEST_IDS_PIPE env var is not set.") if not test_run_pipe: - print("Error[vscode-unittest]: TEST_RUN_PIPE env var is not set.") + print("Error[vscode-unittest]: TEST_RUN_PIPE env var is not set.", file=sys.stderr) raise VSCodeUnittestError("Error[vscode-unittest]: TEST_RUN_PIPE env var is not set.") test_ids = [] cwd = pathlib.Path(start_dir).absolute() @@ -295,11 +295,10 @@ def send_run_data(raw_data, test_run_pipe): # Read the test ids from the file, attempt to delete file afterwords. ids_path = pathlib.Path(run_test_ids_pipe) test_ids = ids_path.read_text(encoding="utf-8").splitlines() - print("Received test ids from temp file.") try: ids_path.unlink() except Exception as e: - print("Error[vscode-pytest]: unable to delete temp file" + str(e)) + print(f"Error[vscode-unittest]: unable to delete temp file: {e}", file=sys.stderr) except Exception as e: # No test ids received from buffer, return error payload @@ -318,10 +317,6 @@ def send_run_data(raw_data, test_run_pipe): is_coverage_run = os.environ.get("COVERAGE_ENABLED") is not None include_branches = False if is_coverage_run: - print( - "COVERAGE_ENABLED env var set, starting coverage. workspace_root used as parent dir:", - workspace_root, - ) import coverage # insert "python_files/lib/python" into the path so packaging can be imported @@ -350,7 +345,6 @@ def send_run_data(raw_data, test_run_pipe): # If no error occurred, we will have test ids to run. if manage_py_path := os.environ.get("MANAGE_PY_PATH"): - print("MANAGE_PY_PATH env var set, running Django test suite.") args = argv[index + 1 :] or [] django_execution_runner(manage_py_path, test_ids, args) else: