Registry / testing / pytest-databases

pytest-databases

JSON →
library0.19.0pypypiunverified

Reusable pytest fixtures for spinning up and tearing down real database containers (PostgreSQL, MySQL, Redis, MongoDB, and more) using Docker or podman. Current version 0.17.0, actively maintained by Litestar-org with monthly releases.

pip install pytest-databases
INSTALL
IMPORT
SIG · PYTEST-DATABASES
P
pytest-databases
testingpythonv0.19.0
Install
3.5s avg
Import
—
Disk
34MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.19.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 35.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.5s · import 0.000s · 36MB
34MB installed
● package 34MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

postgresql_fixture
✓ from pytest_databases import postgresql_fixture
✗ from pytest_databases import postgresql_fixture

Minimal test using the PostgreSQL fixture. The fixture automatically starts a container and yields the connection URL. No configuration needed if Docker is available.

import pytest from pytest_databases import postgresql_fixture # Use the fixture directly pytest_plugins = ['pytest_databases'] def test_database(postgresql_fixture): # postgresql_fixture yields a connection URL string db_url = postgresql_fixture assert 'postgresql://' in db_url
Debug
Known issues
gotchaThe fixture yields a connection URL string, not a database client. You must use it to create your own connection or integrate with an ORM (e.g., SQLAlchemy).
fix
Use the URL with your database library: `engine = create_engine(postgresql_fixture)`.
affects: all
breakingFrom v0.13.0 onward, some fixtures (e.g., Redis) no longer use server isolation mode by default. If you relied on isolated containers per test, you may need to set `isolation_mode='server'` explicitly.
fix
Add `isolation_mode='server'` to the fixture decorator or mark test with `@pytest.mark.isolation_mode('server')`.
affects: >=0.13.0
gotchaThe library requires Docker or podman to be running. If the container runtime is unavailable, tests will fail with a connection error.
fix
Ensure Docker is installed and running, or set the environment variable `PYTEST_DATABASES_DOCKER_CMD` to your container runtime (e.g., `podman`).
affects: all
breakingIn v0.16.0, MongoDB support was added. The fixture name `mongodb_fixture` may conflict with other packages. Import using the full path if needed.
fix
Import as `from pytest_databases import mongodb_fixture` and avoid naming collisions by using aliasing.
affects: >=0.16.0
gotchaSome fixtures (Oracle) require specific Docker images that may not be available on all architectures. In particular, Oracle 18c XE does not support ARM (Apple Silicon).
fix
Use a different database or emulate x86_64 with Rosetta 2. Alternatively, fall back to a cloud-hosted Oracle instance.
affects: >=0.12.0
Upgrade
Version history
0.19.0latest on PyPI · released May 23, 2026
Audit
Dependencies
pytestrequiredCore testing framework required.
dockerrequiredRequired for container management.
Agent activity
19 hits · last 30 days
node
16
Resources
pytest-databases — pip install pytest-databases · libregistry