]> 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:46:32 +0000 (04:46 +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 b5ae6edaa32743d6c38fdcd7ce7ada4ac0f511f8..b423206a5c948c06cddbfc04573c8b83d89598ab 100644 (file)
@@ -230,7 +230,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 734c898bc9b99d39394cdd2d6d3a059213024f72..b40990d6d5ff7dd24d2c1a1bb0b912547669f5c0 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")
@@ -82,7 +91,24 @@ def event_loop(request):
     loop.close()
 
 
+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)