]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: add fixtures to toggle pipeline mode
authorDenis Laxalde <denis.laxalde@dalibo.com>
Thu, 9 Dec 2021 15:37:50 +0000 (16:37 +0100)
committerDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 10 May 2022 13:38:12 +0000 (15:38 +0200)
Also add a pytest mark so that one can run 'pytest -m pipeline' to
select all pipeline-mode tests.

tests/conftest.py
tests/fix_db.py
tests/test_pipeline.py
tests/test_pipeline_async.py

index 6085eeaf675f0d3e042f42e503ec7d249c176ad3..961e3d831f749852255cabfee6804541bdbc94c4 100644 (file)
@@ -29,6 +29,11 @@ def pytest_configure(config):
     for marker in markers:
         config.addinivalue_line("markers", marker)
 
+    config.addinivalue_line(
+        "markers",
+        "pipeline: the test runs with connection in pipeline mode",
+    )
+
 
 def pytest_addoption(parser):
     parser.addoption(
index 1da888341e3014a094024596f81fc27c485be597..9fd3111b008f050914b7c4bf3f38f5accaa53add 100644 (file)
@@ -6,7 +6,7 @@ from typing import List
 
 import psycopg
 from psycopg import pq
-from .utils import check_server_version
+from .utils import check_libpq_version, check_server_version
 
 
 def pytest_addoption(parser):
@@ -43,6 +43,14 @@ def pytest_report_header(config):
     ]
 
 
+def pytest_collection_modifyitems(items):
+    for item in items:
+        for name in item.fixturenames:
+            if name in ("pipeline", "apipeline"):
+                item.add_marker(pytest.mark.pipeline)
+                break
+
+
 def pytest_configure(config):
     # register pg marker
     config.addinivalue_line(
@@ -150,6 +158,19 @@ def conn(dsn, request, tracefile):
     conn.close()
 
 
+@pytest.fixture(params=[True, False], ids=["pipeline=on", "pipeline=off"])
+def pipeline(request, conn):
+    if request.param:
+        msg = check_libpq_version(pq.version(), ">= 14")
+        if msg:
+            pytest.skip(msg)
+        with conn.pipeline() as p:
+            yield p
+        return
+    else:
+        yield None
+
+
 @pytest.fixture
 async def aconn(dsn, request, tracefile):
     """Return an `AsyncConnection` connected to the ``--test-dsn`` database."""
@@ -165,6 +186,19 @@ async def aconn(dsn, request, tracefile):
     await conn.close()
 
 
+@pytest.fixture(params=[True, False], ids=["pipeline=on", "pipeline=off"])
+async def apipeline(request, aconn):
+    if request.param:
+        msg = check_libpq_version(pq.version(), ">= 14")
+        if msg:
+            pytest.skip(msg)
+        async with aconn.pipeline() as p:
+            yield p
+        return
+    else:
+        yield None
+
+
 @pytest.fixture(scope="session")
 def svcconn(dsn):
     """
index 2172c2ff213e75b2e557f73f7b22b6a9d4db9ae6..03a299d3615e4e6e1f8a62b920ea0073f5eff4f7 100644 (file)
@@ -10,7 +10,10 @@ import psycopg
 from psycopg import pq
 from psycopg import errors as e
 
-pytestmark = pytest.mark.libpq(">= 14")
+pytestmark = [
+    pytest.mark.libpq(">= 14"),
+    pytest.mark.pipeline,
+]
 
 
 def test_repr(conn):
index 82a0b5348d116cb7b62291e71541263e2667d605..70468688c85c6f76d4d16293a1b2029faaad27cc 100644 (file)
@@ -11,8 +11,9 @@ from psycopg import pq
 from psycopg import errors as e
 
 pytestmark = [
-    pytest.mark.libpq(">= 14"),
     pytest.mark.asyncio,
+    pytest.mark.libpq(">= 14"),
+    pytest.mark.pipeline,
 ]