Pytest databases
Opinionated first-party agent skills, plugins, subagents, slash commands, and MCP servers for the Litestar framework ecosystem — publishable to Claude Code, Gemini CLI, Codex CLI, Cursor, OpenCode, and VS Code/Copilot from a single repo.
npx -y skills add litestar-org/litestar-skills --skill pytest-databasesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 13 stars13 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Auto-activate for pytest_databases, Docker DB fixtures, PostgreSQL/pgvector/ParadeDB/AlloyDB Omni, MySQL/MariaDB/Dolt, Oracle/SQL Server, CockroachDB/YugabyteDB, MongoDB, Redis/Valkey, Elasticsearch, BigQuery/Spanner, GizmoSQL, Azurite, MinIO, or RustFS tests. Not for mocked databases — use ordinary pytest fixtures.
SKILL.md
6.8 KB, as published. Nobody here has run it
pytest-databases
pytest-databases provides session-scoped, container-backed service fixtures.
This guidance targets the immutable v0.19.0 tag. Load only the plugin modules
the test suite uses. Consume a ready client fixture where one exists; otherwise
connect with the client already used by the project.
Code Style Rules
- Keep database I/O consistent with the project driver. The package's
PostgreSQL connection fixtures use synchronous
psycopg; do notawaittheir methods. - Type service fixtures with the service class from the same plugin module.
- Prefer ready client fixtures when provided. For service-only plugins, build the project's existing client from the service object's host, port, and credentials.
- Keep plugin declarations in the nearest
conftest.py; do not load every backend globally.
Quick Reference
Install and enable
pip install "pytest-databases[postgres]"
# conftest.py
pytest_plugins = ["pytest_databases.docker.postgres"]
The core pytest_databases pytest entry point supplies docker_client and
docker_service. Each database module supplies its own fixtures.
Choose the fixture shape
| Need | Use |
|---|---|
A ready psycopg connection | postgres_connection, a versioned PostgreSQL-family connection, or cockroachdb_connection |
| A ready vendor client | bigquery_client, spanner_connection, mongodb_connection, or an Azure Blob container client |
| Service coordinates for the project's own client | The backend's *_service fixture |
| A specific PostgreSQL-family release | Matching *_NN_service, *_NN_connection, and *_NN_port fixtures |
| Parallel worker isolation | The backend's exact *_xdist_isolation_level fixture from xdist.md |
See reference.md for the exact plugin, service, and
ready-client matrix. Do not infer a *_connection fixture from a
*_service fixture's name.
Workflow
- Install the extra matching the selected backend. Backends with no bundled Python client, such as MySQL, MariaDB, SQL Server, and YugabyteDB, expose service fixtures and expect the project to supply its own driver.
- Add only the required
pytest_databases.docker.<module>entries topytest_plugins. - Prefer a ready client fixture listed in reference.md. Otherwise construct the project's existing client from the typed service fixture.
- Override session-scoped configuration fixtures in
conftest.py. Use environment variables only where 0.19.0 explicitly reads them; see config.md. - For
pytest-xdist, keep the default"database"isolation when the service supports logical namespaces. Override the backend's exact isolation fixture to"server"when each worker needs its own container. - Run the focused integration tests against a Docker-compatible daemon.
Guardrails
- Do not invent connection fixtures. MySQL, MariaDB, SQL Server,
YugabyteDB, Dolt, Redis/KeyDB/Dragonfly, Valkey, MinIO, and RustFS provide no
ready
*_connectionfixture in 0.19.0. - Do not use SQLite fixture names. Version 0.19.0 ships no SQLite plugin.
- Use
azure_blob_*names. The module ispytest_databases.docker.azure_blob, the service isAzureBlobService, and the ready clients areazure_blob_container_clientandazure_blob_async_container_client. - Keep synchronous fixtures synchronous.
postgres_connectionis apsycopg.Connection; callexecute()directly. - Do not assume every backend uses the same xdist fixture name. Azure Blob
uses
azure_blob_xdist_isolation_level; most others usexdist_<backend>_isolation_level. - Do not hand-roll container teardown. The package owns labelled container
lifecycle through
docker_service. - Do not pin a host port without a reason. Dynamic ports avoid conflicts.
Use the 0.19.0
*_portfixture or matching PostgreSQL-family environment variable only when a rootless/container-network constraint requires it.
Validation Checkpoint
- Installed version is
pytest-databases>=0.19.0. -
pytest_pluginsnames an existing module from reference.md. - Every requested fixture exists in that module's 0.19.0 fixture row.
- Service-only backends use the project's own client rather than a
fabricated
*_connectionfixture. - PostgreSQL connection examples use synchronous
psycopgcalls. - Configuration uses an actual fixture or environment variable from config.md.
- Xdist overrides use the backend's exact isolation-fixture name.
- Container-backed tests run against a Docker-compatible daemon.
Example: synchronous PostgreSQL connection
import psycopg
pytest_plugins = ["pytest_databases.docker.postgres"]
def test_postgres_is_ready(
postgres_connection: psycopg.Connection,
) -> None:
row = postgres_connection.execute("SELECT 1").fetchone()
assert row == (1,)
postgres_connection is a synchronous psycopg.Connection. Use an async
driver only by constructing it separately from postgres_service.
References Index
-
Supported database patterns — ready-client and service-only examples.
-
Complete fixture matrix — exact 0.19.0 modules, classes, service fixtures, and client/provider fixtures.
-
Xdist parallel testing — supported isolation fixture names and helper functions.
-
Configuration — fixture overrides and environment variables implemented by 0.19.0.
-
Troubleshooting — runtime, plugin, client, and port failures.
-
Litestar testing — integrate container-backed services with Litestar test clients and dependency overrides.
Official References
- https://pypi.org/project/pytest-databases/0.19.0/
- https://github.com/litestar-org/pytest-databases/tree/v0.19.0
- https://github.com/litestar-org/pytest-databases/tree/v0.19.0/src/pytest_databases/docker
- https://github.com/litestar-org/pytest-databases/tree/v0.19.0/tests