]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
ci: fix proxy-based tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 18 Oct 2025 11:36:12 +0000 (13:36 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 30 Oct 2025 02:46:16 +0000 (02:46 +0000)
Move pproxy_fix out of tests package and use it as a script. Importing
it fails in cibuildwheel otherwise

Exclude the proxy test on Win/macOS. They don't work there, but for all
other test they got skipped as side effects of other markers.

.github/workflows/packages-bin.yml
tests/fix_proxy.py
tools/pproxy_fix.py [moved from tests/pproxy_fix.py with 100% similarity]

index 52dc8de2fab316da878565c0d84e3d82f5dc1988..cb2913bf2540527c6d199fa5e4ba99f05a7c998f 100644 (file)
@@ -86,8 +86,7 @@ jobs:
             ./tools/ci/strip_wheel.sh {wheel}
             && auditwheel repair -w {dest_dir} {wheel}
           CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool
-          CIBW_TEST_COMMAND: >-
-            pytest {project}/tests -m 'not slow and not flakey' --color yes
+          CIBW_TEST_COMMAND: pytest {project}/tests
           CIBW_ENVIRONMENT_PASS_LINUX: LIBPQ_VERSION OPENSSL_VERSION
           CIBW_ENVIRONMENT: >-
             PSYCOPG_IMPL=binary
@@ -98,6 +97,7 @@ jobs:
             LD_LIBRARY_PATH="$LIBPQ_BUILD_PREFIX/lib:$LIBPQ_BUILD_PREFIX/lib64"
             PSYCOPG_TEST_WANT_LIBPQ_BUILD=${{ env.LIBPQ_VERSION }}
             PSYCOPG_TEST_WANT_LIBPQ_IMPORT=${{ env.LIBPQ_VERSION }}
+            PYTEST_ADDOPTS="-m 'not slow and not flakey' --color yes"
 
       - uses: actions/upload-artifact@v4
         with:
@@ -154,8 +154,7 @@ jobs:
           MACOSX_ARCHITECTURE: ${{matrix.arch}}
           CIBW_BEFORE_ALL_MACOS: ./tools/ci/wheel_macos_before_all.sh
           CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool
-          CIBW_TEST_COMMAND: >-
-            pytest {project}/tests -m 'not slow and not flakey' --color yes
+          CIBW_TEST_COMMAND: pytest {project}/tests
           CIBW_ENVIRONMENT: >-
             PG_VERSION=18
             PSYCOPG_IMPL=binary
@@ -164,6 +163,7 @@ jobs:
             PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH"
             PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= ${{env.LIBPQ_VERSION}}"
             PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= ${{env.LIBPQ_VERSION}}"
+            PYTEST_ADDOPTS="-m 'not slow and not flakey and not proxy' --color yes"
 
       - name: Upload artifacts
         uses: actions/upload-artifact@v4
@@ -228,13 +228,13 @@ jobs:
             delvewheel repair -w {dest_dir}
             --no-mangle "libiconv-2.dll;libwinpthread-1.dll" {wheel}
           CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool
-          CIBW_TEST_COMMAND: >-
-            pytest {project}/tests -m "not slow and not flakey" --color yes
+          CIBW_TEST_COMMAND: pytest {project}/tests
           CIBW_ENVIRONMENT_WINDOWS: >-
             PSYCOPG_IMPL=binary
             PSYCOPG_TEST_DSN="host=127.0.0.1 user=postgres"
             PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= 16"
             PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= 16"
+            PYTEST_ADDOPTS="-m 'not slow and not flakey and not proxy' --color yes"
 
       - uses: actions/upload-artifact@v4
         with:
index b2086b250231c1511ea6737d759ae4d5fece129b..e154a17934f4c911c1c20cbf995198547fb43019 100644 (file)
@@ -4,6 +4,7 @@ import time
 import socket
 import logging
 import subprocess as sp
+from pathlib import Path
 from contextlib import contextmanager
 
 import pytest
@@ -34,8 +35,10 @@ def pytest_configure(config):
 def proxy(dsn):
     """Return a proxy to the --test-dsn database"""
     p = Proxy(dsn)
-    yield p
-    p.stop()
+    try:
+        yield p
+    finally:
+        p.stop()
 
 
 class Proxy:
@@ -73,7 +76,8 @@ class Proxy:
             return
 
         logging.info("starting proxy")
-        cmdline = [sys.executable, "-m", "tests.pproxy_fix", "--reuse"]
+        pproxy_fix = str(Path(__file__).parent.parent / "tools/pproxy_fix.py")
+        cmdline = [sys.executable, pproxy_fix, "--reuse"]
         cmdline += ["-l", f"tunnel://:{self.client_port}"]
         cmdline += ["-r", f"tunnel://{self.server_host}:{self.server_port}"]
 
@@ -127,6 +131,10 @@ class Proxy:
                     break
                 time.sleep(0.1)
             else:
-                raise ValueError("the proxy didn't start listening in time")
+                # final shot at connecting, which will raise an exception
+                try:
+                    sock.connect((self.client_host, self.client_port))
+                except Exception as ex:
+                    pytest.fail(f"the proxy didn't start listening in time: {ex}")
 
         logging.info("proxy listening")
similarity index 100%
rename from tests/pproxy_fix.py
rename to tools/pproxy_fix.py