From: Daniele Varrazzo Date: Tue, 24 May 2022 23:03:29 +0000 (+0200) Subject: test(crdb): fix conninfo tests with crdb X-Git-Tag: 3.1~49^2~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b358a43fc8c75ae57fcb74eb4df4082d6a9676e;p=thirdparty%2Fpsycopg.git test(crdb): fix conninfo tests with crdb --- diff --git a/tests/fix_db.py b/tests/fix_db.py index a069e9d95..462732701 100644 --- a/tests/fix_db.py +++ b/tests/fix_db.py @@ -152,11 +152,7 @@ def conn(dsn, request, tracefile): """Return a `Connection` connected to the ``--test-dsn`` database.""" check_connection_version(request.node) - cls = psycopg.Connection - if crdb_version: - cls = CrdbConnection - - conn = cls.connect(dsn) + conn = connection_class().connect(dsn) with maybe_trace(conn.pgconn, tracefile, request.function): yield conn conn.close() @@ -205,6 +201,14 @@ async def apipeline(request, aconn): yield None +def connection_class(): + cls = psycopg.Connection + if crdb_version: + cls = CrdbConnection + + return cls + + @pytest.fixture(scope="session") def svcconn(session_dsn): """ diff --git a/tests/test_conninfo.py b/tests/test_conninfo.py index a94a101bd..70571d286 100644 --- a/tests/test_conninfo.py +++ b/tests/test_conninfo.py @@ -10,6 +10,7 @@ from psycopg.conninfo import make_conninfo, conninfo_to_dict, ConnectionInfo from psycopg.conninfo import resolve_hostaddr_async from psycopg._encodings import pg2pyenc +from .fix_db import connection_class from .fix_crdb import crdb_encoding snowman = "\u2603" @@ -148,11 +149,11 @@ class TestConnectionInfo: dsn.pop("application_name", None) monkeypatch.delenv("PGAPPNAME", raising=False) - with psycopg.connect(**dsn) as conn: + with connection_class().connect(**dsn) as conn: assert "application_name" not in conn.info.get_parameters() monkeypatch.setenv("PGAPPNAME", "hello test") - with psycopg.connect(**dsn) as conn: + with connection_class().connect(**dsn) as conn: assert conn.info.get_parameters()["application_name"] == "hello test" def test_dsn_env(self, dsn, monkeypatch): @@ -160,11 +161,11 @@ class TestConnectionInfo: dsn.pop("application_name", None) monkeypatch.delenv("PGAPPNAME", raising=False) - with psycopg.connect(**dsn) as conn: + with connection_class().connect(**dsn) as conn: assert "application_name=" not in conn.info.dsn monkeypatch.setenv("PGAPPNAME", "hello test") - with psycopg.connect(**dsn) as conn: + with connection_class().connect(**dsn) as conn: assert "application_name='hello test'" in conn.info.dsn def test_status(self, conn): @@ -296,7 +297,7 @@ class TestConnectionInfo: ) def test_encoding_env_var(self, dsn, monkeypatch, enc, out, codec): monkeypatch.setenv("PGCLIENTENCODING", enc) - with psycopg.connect(dsn) as conn: + with connection_class().connect(dsn) as conn: clienc = conn.info.parameter_status("client_encoding") assert clienc if conn.info.vendor == "PostgreSQL":