]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Allow to use the pg(ver) marker with the module pytestmark
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Oct 2021 03:29:25 +0000 (05:29 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 4 Oct 2021 12:44:13 +0000 (14:44 +0200)
tests/fix_db.py

index 738d06a6ef0ed77c54786790ea31133bbec4b5ce..74e16b40919d128e1c960c43a5a2db3f9a1345a7 100644 (file)
@@ -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