Skip to content

Commit c7a00c9

Browse files
authored
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.
1 parent cd5ecb9 commit c7a00c9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

python_files/vscode_pytest/run_pytest_script.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ def run_pytest(args):
5555
try:
5656
# Read the test ids from the file and run pytest.
5757
ids = ids_path.read_text(encoding="utf-8").splitlines()
58-
arg_array = ["-p", "vscode_pytest", *args, *ids]
59-
print("Running pytest with args: " + str(arg_array))
60-
pytest.main(arg_array)
6158
except Exception as e:
6259
print("Error[vscode-pytest]: unable to read testIds from temp file" + str(e))
6360
run_pytest(args)
61+
else:
62+
arg_array = ["-p", "vscode_pytest", *args, *ids]
63+
print("Running pytest with args: " + str(arg_array))
64+
pytest.main(arg_array)
6465
finally:
6566
# Delete the test ids temp file.
6667
try:

0 commit comments

Comments
 (0)