From c7a00c9d6a52be5925e48691d08dfb6a4f6e21f7 Mon Sep 17 00:00:00 2001 From: apuly Date: Fri, 14 Nov 2025 08:13:57 +0000 Subject: [PATCH] Don't re-run pytest when an exception in a test occurs The general `except` around the pytest run was causing tests to run twice if the exception handling of pytest is disabled. From the comment in the code it seems the exception handling is only there for when reading the test IDs break, so it shouldn't be required around the pytest main call. Disabling the exception handling can be practical for debugging tests, as this starts up the python debugger within vscode. Currently however, this requires manually patching the run_pytest_script.py, which needs to be re-done every vscode update. --- python_files/vscode_pytest/run_pytest_script.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python_files/vscode_pytest/run_pytest_script.py b/python_files/vscode_pytest/run_pytest_script.py index 8d30ba7e4399..50ab12a35423 100644 --- a/python_files/vscode_pytest/run_pytest_script.py +++ b/python_files/vscode_pytest/run_pytest_script.py @@ -55,12 +55,13 @@ def run_pytest(args): try: # Read the test ids from the file and run pytest. ids = ids_path.read_text(encoding="utf-8").splitlines() - arg_array = ["-p", "vscode_pytest", *args, *ids] - print("Running pytest with args: " + str(arg_array)) - pytest.main(arg_array) except Exception as e: print("Error[vscode-pytest]: unable to read testIds from temp file" + str(e)) run_pytest(args) + else: + arg_array = ["-p", "vscode_pytest", *args, *ids] + print("Running pytest with args: " + str(arg_array)) + pytest.main(arg_array) finally: # Delete the test ids temp file. try: