From: Daniele Varrazzo Date: Sat, 2 Oct 2021 03:29:25 +0000 (+0200) Subject: Allow to use the pg(ver) marker with the module pytestmark X-Git-Tag: 3.0~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c669e41d0e62be6e1d3c836ed856f31f290fdb12;p=thirdparty%2Fpsycopg.git Allow to use the pg(ver) marker with the module pytestmark --- diff --git a/tests/fix_db.py b/tests/fix_db.py index 738d06a6e..74e16b409 100644 --- a/tests/fix_db.py +++ b/tests/fix_db.py @@ -23,6 +23,14 @@ def pytest_configure(config): ) +def pytest_runtest_setup(item): + # Copy the want marker on the function so we can check the version + # after the connection has been created. + want_ver = [m.args[0] for m in item.iter_markers() if m.name == "pg"] + if want_ver: + item.function.want_pg_version = want_ver[0] + + @pytest.fixture(scope="session") def dsn(request): """Return the dsn used to connect to the `--test-dsn` database.""" @@ -133,11 +141,9 @@ class ListPopAll(list): def check_connection_version(got, function): - if not hasattr(function, "pytestmark"): + if not hasattr(function, "want_pg_version"): return - want = [m.args[0] for m in function.pytestmark if m.name == "pg"] - if want: - return check_server_version(got, want[0]) + return check_server_version(got, function.want_pg_version) @pytest.fixture