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-databasesVerified import paths — ran on the pinned version, not inferred.
Minimal test using the PostgreSQL fixture. The fixture automatically starts a container and yields the connection URL. No configuration needed if Docker is available.
Use the URL with your database library: `engine = create_engine(postgresql_fixture)`.
Add `isolation_mode='server'` to the fixture decorator or mark test with `@pytest.mark.isolation_mode('server')`.Ensure Docker is installed and running, or set the environment variable `PYTEST_DATABASES_DOCKER_CMD` to your container runtime (e.g., `podman`).
Import as `from pytest_databases import mongodb_fixture` and avoid naming collisions by using aliasing.
Use a different database or emulate x86_64 with Rosetta 2. Alternatively, fall back to a cloud-hosted Oracle instance.