]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Add mark for pool tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 6 Jan 2022 23:23:46 +0000 (00:23 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 7 Jan 2022 01:46:51 +0000 (02:46 +0100)
Don't auto-skip pool test if import fails. This would miss serious
problems leading to the pool not being importable. If someone wants to
skip the pool tests they can use `-m 'not pool'` now.

tests/conftest.py
tests/pool/fix_pool.py [new file with mode: 0644]
tests/pool/test_pool.py
tests/pool/test_pool_async.py
tests/pool/test_sched.py
tests/pool/test_sched_async.py

index 96331e903663d6d271275f7f541402724c438510..588fa8affc4beb374739f559f15f6d70ea19e2e2 100644 (file)
@@ -11,35 +11,23 @@ pytest_plugins = (
     "tests.fix_faker",
     "tests.fix_proxy",
     "tests.fix_psycopg",
+    "tests.pool.fix_pool",
 )
 
 
 def pytest_configure(config):
-    # register slow marker
-    config.addinivalue_line(
-        "markers", "slow: this test is kinda slow (skip with -m 'not slow')"
-    )
-
-    # There are troubles on travis with these kind of tests and I cannot
-    # catch the exception for my life.
-    config.addinivalue_line(
-        "markers", "subprocess: the test import psycopg after subprocess"
-    )
-
-    config.addinivalue_line(
-        "markers",
+    markers = [
+        "slow: this test is kinda slow (skip with -m 'not slow')",
+        # There are troubles on travis with these kind of tests and I cannot
+        # catch the exception for my life.
+        "subprocess: the test import psycopg after subprocess",
         "timing: the test is timing based and can fail on cheese hardware",
-    )
-
-    config.addinivalue_line(
-        "markers",
         "dns: the test requires dnspython to run",
-    )
-
-    config.addinivalue_line(
-        "markers",
         "postgis: the test requires the PostGIS extension to run",
-    )
+    ]
+
+    for marker in markers:
+        config.addinivalue_line("markers", marker)
 
 
 def pytest_addoption(parser):
diff --git a/tests/pool/fix_pool.py b/tests/pool/fix_pool.py
new file mode 100644 (file)
index 0000000..13768c0
--- /dev/null
@@ -0,0 +1,14 @@
+import pytest
+
+
+def pytest_configure(config):
+    config.addinivalue_line(
+        "markers", "pool: test related to the psycopg_pool package"
+    )
+
+
+def pytest_collection_modifyitems(items):
+    # Add the pool markers to all the tests in the pool package
+    for item in items:
+        if "/pool/" in item.nodeid:
+            item.add_marker(pytest.mark.pool)
index 14297cdbf0a5791756cc889b43a432a3f4d8aa29..45cc33b4e9938d60e44a6a8906c5b886bf5390ff 100644 (file)
@@ -11,14 +11,11 @@ import psycopg
 from psycopg.pq import TransactionStatus
 from psycopg._compat import Counter
 
-pytestmark = []
-
 try:
-    from psycopg_pool import ConnectionPool  # noqa: F401
-except ImportError as ex:
-    pytestmark.append(pytest.mark.skip(reason=str(ex)))
-else:
     import psycopg_pool as pool
+except ImportError:
+    # Tests should have been skipped if the package is not available
+    pass
 
 
 def test_package_version(mypy):
index 7d75d7ba6e8dc4742597fcb8726fae6723f753b2..923fb84e0cdb231ae61b4f0f008f23151d2d0fee 100644 (file)
@@ -10,6 +10,12 @@ import psycopg
 from psycopg.pq import TransactionStatus
 from psycopg._compat import create_task, Counter
 
+try:
+    import psycopg_pool as pool
+except ImportError:
+    # Tests should have been skipped if the package is not available
+    pass
+
 pytestmark = [
     pytest.mark.asyncio,
     pytest.mark.skipif(
@@ -18,13 +24,6 @@ pytestmark = [
     ),
 ]
 
-try:
-    from psycopg_pool import AsyncConnectionPool  # noqa: F401
-except ImportError as ex:
-    pytestmark.append(pytest.mark.skip(reason=str(ex)))
-else:
-    import psycopg_pool as pool
-
 
 async def test_defaults(dsn):
     async with pool.AsyncConnectionPool(dsn) as p:
index a3bdd5cfaa074d578589f5ea4e935a25e13921e6..abdb97e9ed3283ac01708bb67e60bc27cba48594 100644 (file)
@@ -5,12 +5,13 @@ from threading import Thread
 
 import pytest
 
-pytestmark = [pytest.mark.timing]
-
 try:
     from psycopg_pool.sched import Scheduler
-except ImportError as ex:
-    pytestmark.append(pytest.mark.skip(reason=str(ex)))
+except ImportError:
+    # Tests should have been skipped if the package is not available
+    pass
+
+pytestmark = [pytest.mark.timing]
 
 
 @pytest.mark.slow
index 651e9038f4c72745b7fb48c77444b8719348c322..6c3e23d7bcfcf08ba969129375f4d10bb1d3f32a 100644 (file)
@@ -7,12 +7,13 @@ import pytest
 
 from psycopg._compat import create_task
 
-pytestmark = [pytest.mark.asyncio, pytest.mark.timing]
-
 try:
     from psycopg_pool.sched import AsyncScheduler
-except ImportError as ex:
-    pytestmark.append(pytest.mark.skip(reason=str(ex)))
+except ImportError:
+    # Tests should have been skipped if the package is not available
+    pass
+
+pytestmark = [pytest.mark.asyncio, pytest.mark.timing]
 
 
 @pytest.mark.slow