]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: fail test session in case of segfault
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 15 Sep 2022 01:07:57 +0000 (02:07 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 15 Sep 2022 01:20:33 +0000 (02:20 +0100)
Before that, tox reruns would have made tests pass, because failed tests
wouldn't have gotten a chance to be written in the cache.

tests/conftest.py

index 598c36aa4f4909f67b5f5666a13a710d5bc1d388..e098a8e748c6ba3ae484fefa65abc685a446d307 100644 (file)
@@ -66,6 +66,19 @@ def pytest_report_header(config):
 
 
 def pytest_sessionstart(session):
+    # Detect if there was a segfault in the previous run.
+    #
+    # In case of segfault, pytest doesn't get a chance to write failed tests
+    # in the cache. As a consequence, tox retries would find no test failed and
+    # assume that all tests passed in the previous run, making the whole test pass.
+    #
+    # Note: The cache is in .pytest_cache/
+    cache = session.config.cache
+    if cache.get("segfault", False):
+        session.warn(Warning("Previous run resulted in segfault! Not running any test"))
+        raise session.Failed
+    cache.set("segfault", True)
+
     # Configure the async loop.
     loop = session.config.getoption("--loop")
     if loop == "uvloop":
@@ -83,6 +96,9 @@ allow_fail_messages: List[str] = []
 
 
 def pytest_sessionfinish(session, exitstatus):
+    # Mark the test run successful (in the sense -weak- that we didn't segfault).
+    session.config.cache.set("segfault", False)
+
     no_collect_ok = session.config.getoption("--no-collect-ok")
     if exitstatus == pytest.ExitCode.NO_TESTS_COLLECTED and no_collect_ok:
         session.exitstatus = pytest.ExitCode.OK