]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Handle missing test_results due to pytest runner interrupt
authorTom Krizek <tkrizek@isc.org>
Wed, 22 Mar 2023 14:52:05 +0000 (15:52 +0100)
committerTom Krizek <tkrizek@isc.org>
Mon, 22 May 2023 12:11:40 +0000 (14:11 +0200)
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

index eaeb74e4e50c5878758a4d0c8d09bca59c324015..3d1cfb7c8515befe99ff65980bb0e91a11820f59 100644 (file)
@@ -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)