From: Daniele Varrazzo Date: Thu, 15 Sep 2022 01:07:57 +0000 (+0100) Subject: test: fail test session in case of segfault X-Git-Tag: 3.1.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=052534ff0c8d947ae4d3b97a655c3d643ff8873a;p=thirdparty%2Fpsycopg.git test: fail test session in case of segfault Before that, tox reruns would have made tests pass, because failed tests wouldn't have gotten a chance to be written in the cache. --- diff --git a/tests/conftest.py b/tests/conftest.py index 598c36aa4..e098a8e74 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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