From 3f7b714c1265f2aaf5e8c3a93ecee223a783a34a Mon Sep 17 00:00:00 2001 From: Shanush Prema Thasarathan Date: Tue, 15 Nov 2022 20:07:00 +1100 Subject: [PATCH] Replace pytest.exit with FileNotFoundError so that error is reported properly. This is because xdist incorrect intercepts a pytest.exit as a keyboard interrupt and removes the error message. --- tests/README.md | 4 ++++ tests/conftest.py | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/README.md b/tests/README.md index 6ba72e4ace..ce66212870 100644 --- a/tests/README.md +++ b/tests/README.md @@ -108,6 +108,10 @@ Commonly used options like `-n auto` are added to addopts within the [pytest] se The `-v` (or `--verbose`) option is helpful to see what is going on. +If an error occurs that lacks details or if you see a "keyboard interrupt" reported by xdist, try running pytest with `-n 0`. This may provide more accurate details for the source of the error. + +Avoid using pytest.exit in the pytest test code, and instead raise an exception. This is because xdist does not capture pytest.exit properly, hiding the error message and reporting a false keyboard interrupt. + ## Custom options `Note:` diff --git a/tests/conftest.py b/tests/conftest.py index da1c26e54a..a4678c7d28 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -174,7 +174,7 @@ def dut_encoder_path(request) -> str: path = str(path.resolve()) if not os.path.isfile(path): - pytest.exit(f"\nDUT encoder binary {path} not found!\n!") + raise FileNotFoundError(f"DUT encoder binary {path} not found!\n!") return path @@ -296,7 +296,7 @@ def ref_encoder_path(request) -> str: path = str(path.resolve()) if not os.path.isfile(path): - pytest.exit(f"\nREF encoder binary {path} not found!\n!") + raise FileNotFoundError(f"REF encoder binary {path} not found!\n!") return path @@ -322,7 +322,7 @@ def dut_decoder_path(request) -> str: path = str(path.resolve()) if not os.path.isfile(path): - pytest.exit(f"\nDUT decoder binary {path} not found!\n!") + raise FileNotFoundError(f"DUT decoder binary {path} not found!\n!") return path @@ -430,7 +430,7 @@ def ref_decoder_path(request) -> str: path = str(path.resolve()) if not os.path.isfile(path): - pytest.exit(f"\nREF decoder binary {path} not found!\n!") + raise FileNotFoundError(f"REF decoder binary {path} not found!\n!") return path @@ -468,7 +468,7 @@ def reference_path(request) -> str: if request.config.option.update_ref == "0": if not os.path.isdir(path): - pytest.exit(f"\nREF path {path} not found!\nPlease generate the references, first!\n!") + raise FileNotFoundError(f"REF path {path} not found!\nPlease generate the references, first!\n!") return path -- GitLab