)
-def pytest_runtest_setup(item):
- for m in item.iter_markers(name="crdb"):
- if len(m.args) > 1:
- raise TypeError("max one argument expected")
- kwargs_unk = set(m.kwargs) - {"reason"}
- if kwargs_unk:
- raise TypeError(f"unknown keyword arguments: {kwargs_unk}")
-
- # Copy the want marker on the function so we can check the version
- # after the connection has been created.
- item.function.want_crdb = m.args[0] if m.args else "only"
- item.function.crdb_reason = m.kwargs.get("reason")
-
-
-def check_crdb_version(got, func):
+def check_crdb_version(got, mark):
"""
Verify if the CockroachDB version is a version accepted.
and skips the test if the server version doesn't match what expected.
"""
- want = func.want_crdb
+ assert len(mark.args) <= 1
+ assert not (set(mark.kwargs) - {"reason"})
+ want = mark.args[0] if mark.args else "only"
msg = None
if got is None:
if want == "only":
- return "skipping test: CockroachDB only"
+ msg = "skipping test: CockroachDB only"
else:
if want == "only":
pass
elif want == "skip":
- msg = crdb_skip_message(func.crdb_reason)
+ msg = crdb_skip_message(mark.kwargs.get("reason"))
else:
msg = check_version(got, want, "CockroachDB")
)
-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 session_dsn(request):
"""
@pytest.fixture
def dsn(session_dsn, request):
"""Return the dsn used to connect to the `--test-dsn` database."""
- check_connection_version(request.function)
+ check_connection_version(request.node)
return session_dsn
@pytest.fixture
def pgconn(dsn, request, tracefile):
"""Return a PGconn connection open to `--test-dsn`."""
- check_connection_version(request.function)
+ check_connection_version(request.node)
conn = pq.PGconn.connect(dsn.encode())
if conn.status != pq.ConnStatus.OK:
@pytest.fixture
def conn(dsn, request, tracefile):
"""Return a `Connection` connected to the ``--test-dsn`` database."""
- check_connection_version(request.function)
+ check_connection_version(request.node)
cls = psycopg.Connection
if crdb_version:
@pytest.fixture
async def aconn(dsn, request, tracefile):
"""Return an `AsyncConnection` connected to the ``--test-dsn`` database."""
- check_connection_version(request.function)
+ check_connection_version(request.node)
cls = psycopg.AsyncConnection
if crdb_version:
return out
-def check_connection_version(function):
+def check_connection_version(node):
try:
pg_version
except NameError:
# First connection creation failed. Let the tests fail.
- return None
+ pytest.fail("server version not available")
- if hasattr(function, "want_pg_version"):
- msg = check_server_version(pg_version, function)
- if msg:
- pytest.skip(msg)
+ for mark in node.iter_markers():
+ if mark.name == "pg":
+ assert len(mark.args) == 1
+ msg = check_server_version(pg_version, mark.args[0])
+ if msg:
+ pytest.skip(msg)
- if hasattr(function, "want_crdb"):
- from .fix_crdb import check_crdb_version
-
- msg = check_crdb_version(crdb_version, function)
- if msg:
- pytest.skip(msg)
+ elif mark.name == "crdb":
+ from .fix_crdb import check_crdb_version
- return None
+ msg = check_crdb_version(crdb_version, mark)
+ if msg:
+ pytest.skip(msg)
@pytest.fixture
return check_version(got, want, "libpq")
-def check_server_version(got, function):
+def check_server_version(got, want):
"""
Verify if the server version is a version accepted.
and skips the test if the server version doesn't match what expected.
"""
- want = function.want_pg_version
return check_version(got, want, "server")