From: Denis Laxalde Date: Thu, 9 Dec 2021 15:37:50 +0000 (+0100) Subject: test: add fixtures to toggle pipeline mode X-Git-Tag: 3.1~110^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=500f90b47a289d8de13049d333ad908e8b22da05;p=thirdparty%2Fpsycopg.git test: add fixtures to toggle pipeline mode Also add a pytest mark so that one can run 'pytest -m pipeline' to select all pipeline-mode tests. --- diff --git a/tests/conftest.py b/tests/conftest.py index 6085eeaf6..961e3d831 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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( diff --git a/tests/fix_db.py b/tests/fix_db.py index 1da888341..9fd3111b0 100644 --- a/tests/fix_db.py +++ b/tests/fix_db.py @@ -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): """ diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 2172c2ff2..03a299d36 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -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): diff --git a/tests/test_pipeline_async.py b/tests/test_pipeline_async.py index 82a0b5348..70468688c 100644 --- a/tests/test_pipeline_async.py +++ b/tests/test_pipeline_async.py @@ -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, ]