Reusable database fixtures for any and all databases.
Maintained. Last release 3 weeks ago, commits in 3 of the last 26 weeks. Weaker on commit activity.
pip install pytest-databasesReusable database fixtures for any and all databases.
Maintained. Last release 3 weeks ago, commits in 3 of the last 26 weeks. Weaker on commit activity.
pip install pytest-databases| Community |
| Meta |
Ready-made database fixtures for your pytest tests.
pytest-databases uses the Docker Python SDK to manage the startup and shutdown of database services in containers. The following databases are currently available:
Quick install for postgres:
pip install pytest-databases[postgres]
conftest.py:pytest_plugins = ["pytest_databases.docker.postgres"]
from pytest_databases.docker.postgres import PostgresService
import psycopg
def test_one(postgres_service: PostgresService) -> None:
with psycopg.connect(
f"postgresql://{postgres_service.user}:{postgres_service.password}@{postgres_service.host}:{postgres_service.port}/{postgres_service.database}",
autocommit=True,
) as conn:
result = conn.execute("SELECT 1")
assert result
Full documentation is available at https://litestar-org.github.io/pytest-databases/latest/
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
Use instead of pytest-databases: tools that do the same job, closest first.
Compare with pytest-mock-resources →Compare with pytest-postgresql →Compare with pytest-mysql →Compare all 4 →
A pytest plugin for easily instantiating reproducible mock resources.
Postgresql fixtures and fixture factories for Pytest.
MySQL process and client fixtures for pytest
Python testing library for PGlite - in-memory PostgreSQL for tests
Use together with pytest-databases: extensions, drivers, servers and companion tools.