]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Allow one test to fail on Windows C implementation
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 14 Jan 2022 03:44:56 +0000 (04:44 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 14 Jan 2022 03:44:56 +0000 (04:44 +0100)
This test doesn't run in tox, so it doesn't benefit from repeats, and it
fails often indeed on flakey tests.

Add pytest option to tolerate a number of failures, and use it.

.github/workflows/tests.yml
tests/conftest.py

index 8a42d808ff56d3bf77f0aaf2b65a9cd725b5d685..3e6ec0565ac1d2e0c41ce7267ef544256cd81bea 100644 (file)
@@ -226,7 +226,11 @@ jobs:
           &"pip" install @(Get-ChildItem wheelhouse\*.whl)
           # Fix the path for the tests using ctypes
           $env:Path = "C:\Program Files\PostgreSQL\14\bin\;$env:Path"
-          pytest
+          # We don't repeat failed tests as tox does. So allow one failure,
+          # typically reserved to a flakey test.
+          # We may hide a regular failure, yes, but then maybe a flakey test
+          # would allow us to find it...
+          pytest --allow-fail=1
 
 
   # }}}
index f9911aa16055fe5af8976d8ccd10d9a8b3146ed4..fc48314743e043dfdc101b47763364b6e5f68747 100644 (file)
@@ -1,5 +1,6 @@
 import sys
 import asyncio
+from typing import List
 
 import pytest
 
@@ -44,6 +45,14 @@ def pytest_addoption(parser):
         " (useful with --lfnf=none).",
     )
 
+    parser.addoption(
+        "--allow-fail",
+        metavar="NUM",
+        type=int,
+        default=0,
+        help="Tolerate up to NUM failures. Use carefully.",
+    )
+
 
 def pytest_report_header(config):
     loop = config.getoption("--loop")
@@ -67,7 +76,24 @@ def pytest_sessionstart(session):
         asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
 
 
+allow_fail_messages: List[str] = []
+
+
 def pytest_sessionfinish(session, exitstatus):
     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
+
+    allow_fail = session.config.getoption("--allow-fail")
+    if exitstatus == pytest.ExitCode.TESTS_FAILED:
+        if session.testsfailed <= allow_fail:
+            allow_fail_messages.append(f"Tests failed: {session.testsfailed}")
+            allow_fail_messages.append(f"Failures allowed: {allow_fail}")
+            session.exitstatus = pytest.ExitCode.OK
+
+
+def pytest_terminal_summary(terminalreporter, exitstatus, config):
+    if allow_fail_messages:
+        terminalreporter.section("failed tests ignored")
+        for msg in allow_fail_messages:
+            terminalreporter.line(msg)