From: Daniele Varrazzo Date: Sat, 18 Oct 2025 11:36:12 +0000 (+0200) Subject: ci: fix proxy-based tests X-Git-Tag: 3.2.11~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2905e07f0fa2fec4dd67225950d728e1e8c66c6a;p=thirdparty%2Fpsycopg.git ci: fix proxy-based tests 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. --- diff --git a/.github/workflows/packages-bin.yml b/.github/workflows/packages-bin.yml index 2291abc00..2fb061765 100644 --- a/.github/workflows/packages-bin.yml +++ b/.github/workflows/packages-bin.yml @@ -80,8 +80,7 @@ jobs: ./tools/build/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 @@ -92,6 +91,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: @@ -153,8 +153,7 @@ jobs: MACOSX_ARCHITECTURE: ${{matrix.arch}} CIBW_BEFORE_ALL_MACOS: ./tools/build/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 @@ -163,6 +162,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: diff --git a/tests/fix_proxy.py b/tests/fix_proxy.py index b2086b250..e154a1793 100644 --- a/tests/fix_proxy.py +++ b/tests/fix_proxy.py @@ -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") diff --git a/tests/pproxy_fix.py b/tools/pproxy_fix.py similarity index 100% rename from tests/pproxy_fix.py rename to tools/pproxy_fix.py