From 0a063f51d39ee72b46dba0795701de17012e942a Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Wed, 22 Mar 2023 15:52:05 +0100 Subject: [PATCH] Handle missing test_results due to pytest runner interrupt If pytest execution is interrupted, the hook that exposes test_results to the pytest session is never called so the results can't be interpreted. --- bin/tests/system/conftest.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/tests/system/conftest.py b/bin/tests/system/conftest.py index eaeb74e4e5..3d1cfb7c85 100644 --- a/bin/tests/system/conftest.py +++ b/bin/tests/system/conftest.py @@ -316,10 +316,17 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0": def get_test_result(): """Aggregate test results from all individual tests from this module into a single result: failed > skipped > passed.""" + try: + all_test_results = request.session.test_results + except AttributeError: + # This may happen if pytest execution is interrupted and + # pytest_runtest_makereport() is never called. + logger.debug("can't obtain test results, test run was interrupted") + return "error" test_results = { - node.nodeid: request.session.test_results[node.nodeid] + node.nodeid: all_test_results[node.nodeid] for node in request.node.collect() - if node.nodeid in request.session.test_results + if node.nodeid in all_test_results } logger.debug(test_results) assert len(test_results)