]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: fail test session in case of segfault maint-3.0
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:23:31 +0000 (02:23 +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 f435189e2340baced9582ffc8b10ddce400ea3d8..10894c5096ace2a7556aacf70d8cb6aa6221eb32 100644 (file)
@@ -91,10 +91,28 @@ def event_loop(request):
     loop.close()
 
 
+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)
+
+
 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