pytest_adbc_replay.plugin¶
pytest_adbc_replay.plugin
¶
pytest-adbc-replay plugin: hooks, CLI option, fixture registration.
pytest_addoption
¶
Register --adbc-record CLI option and ini configuration keys.
Source code in src/pytest_adbc_replay/plugin.py
pytest_configure
¶
Register adbc_cassette marker to suppress PytestUnknownMarkWarning.
Source code in src/pytest_adbc_replay/plugin.py
pytest_sessionstart
¶
Monkeypatch ADBC driver connect() for each driver in adbc_auto_patch.
Source code in src/pytest_adbc_replay/plugin.py
pytest_runtest_setup
¶
Track the currently-running test item for monkeypatched connect() resolution.
pytest_runtest_teardown
¶
Clear current item and close all connections opened during this test.
Source code in src/pytest_adbc_replay/plugin.py
pytest_report_header
¶
Display active record mode in the pytest session header (DX-01).
Source code in src/pytest_adbc_replay/plugin.py
adbc_param_serialisers
¶
Session-scoped fixture providing custom parameter serialisers for ADBC replay.
Override this fixture in your conftest.py to register custom serialisers for non-JSON-native parameter types (e.g. numpy arrays, custom date wrappers).
Returns:
| Type | Description |
|---|---|
dict[Any, dict[str, Any]] | None
|
A dict mapping Python types to serialiser dicts, or None to use defaults. |
dict[Any, dict[str, Any]] | None
|
Each serialiser dict must have "serialise" and "type_tag" keys, and |
dict[Any, dict[str, Any]] | None
|
optionally a "deserialise" key. |
Example::
import pytest
import numpy as np
from pytest_adbc_replay import NO_DEFAULT_SERIALISERS
@pytest.fixture(scope="session")
def adbc_param_serialisers():
return {
np.int64: {
"type_tag": "numpy.int64",
"serialise": lambda v: {"value": int(v)},
},
}
Source code in src/pytest_adbc_replay/plugin.py
adbc_scrubber
¶
Session-scoped fixture providing a scrubbing callback for recorded data.
Override this fixture in your conftest.py to register a callback that scrubs sensitive values before they are written to cassette files.
The callback receives (params, driver_name) where params is the
already config-scrubbed parameter dict (after adbc_scrub_keys is
applied) and driver_name is the ADBC driver module name string.
If the callback returns None, the config-scrubbed params are used
unchanged. If it returns a dict, that dict replaces the params.
Returns:
| Type | Description |
|---|---|
object
|
A callable |
object
|
to use no fixture-level scrubbing. |
Example::
@pytest.fixture(scope="session")
def adbc_scrubber():
def scrub(params, driver_name):
if isinstance(params, dict):
return {k: "REDACTED" if k == "secret" else v
for k, v in params.items()}
return params
return scrub
Source code in src/pytest_adbc_replay/plugin.py
adbc_replay
¶
adbc_replay(
request: FixtureRequest,
adbc_param_serialisers: dict[Any, dict[str, Any]]
| None,
adbc_scrubber: object,
) -> ReplaySession
Session-scoped fixture providing ADBC record/replay state.
Returns a ReplaySession whose .wrap() method creates per-test ReplayConnection instances. Call .wrap() from your function-scoped fixture -- it reads the adbc_cassette marker from request.node.
Example::
@pytest.fixture
def my_connection(adbc_replay, request):
return adbc_replay.wrap(
"adbc_driver_snowflake",
db_kwargs={"uri": os.environ["SNOWFLAKE_URI"]},
request=request,
)
Source code in src/pytest_adbc_replay/plugin.py
adbc_connect
¶
Function-scoped factory fixture for creating ADBC replay connections explicitly.
Use this as the escape hatch when adbc_auto_patch is not appropriate --
for example, when you need a session-scoped or module-scoped connection, or
when you prefer explicit control over connection creation.
Returns a callable: (driver_module_name: str, **db_kwargs) -> ReplayConnection
The fixture closes all opened connections when the test finishes. Cassette paths follow the per-driver subdirectory layout used by auto-patch.
Example::
@pytest.mark.adbc_cassette("my_test")
def test_my_query(adbc_connect):
conn = adbc_connect("adbc_driver_snowflake.dbapi", uri=os.environ["SF_URI"])
cursor = conn.cursor()
cursor.execute("SELECT 1")