pytest-databases
Reusable database fixtures for any and all databases.
Decision gist · record as of 2026-08-14
Yes, if you need real database testing in a containerized environment. The low install friction, active maintenance, permissive license, and broad database support make it a solid choice for integration tests. The main gotcha is the Docker dependency—you must have Docker running, and container startup adds latency per test. For unit tests or projects that cannot use Docker, this is not the right tool.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Docker to be installed and running on the system; the package manages database container lifecycle but does not provide Docker itself.
- Low friction installation with a pure Python wheel.
- Maintenance is active with a recent release; the package is in Beta status and depends on docker, filelock, and pytest—all stable, widely-used libraries.
License · maintenance · safety
MIT (permissive) — MIT license is permissive; you can use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
last release 2026-05-23 (83 days) · last repo commit 2026-07-22 · 58 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 74,438 downloads/mo, #14,830 on PyPI
Alternatives
Verify before relying
pip install pytest-databases[postgres]
# In conftest.py:
pytest_plugins = ["pytest_databases.docker.postgres"]
# In test file:
from pytest_databases.docker.postgres import PostgresService
def test_example(postgres_service: PostgresService):
# Use postgres_service.host, .port, .user, .password, .database- Whether all listed database versions (Postgres 12–18, MySQL 5.6–8, Oracle 18c/23c, SQL Server 2022) are actively maintained in the fixture set.
- Performance characteristics and overhead of spinning up containers per test or per session.
- Whether the package handles cleanup and resource limits to prevent orphaned containers in CI/CD environments.
What it is and what it does
pytest-databases is a pytest plugin that provides ready-made fixtures for running database services in Docker containers during tests. Instead of mocking or using in-memory databases, it lets you test against real database instances—Postgres, MySQL, Oracle, SQL Server, Redis, Elasticsearch, and others—each isolated in its own container. The plugin handles container startup, configuration, and teardown automatically.
You declare which database you want in your conftest.py, then inject the service fixture into your test functions. The fixture exposes connection details (host, port, user, password, database name) so you can connect with your normal database client library. This approach trades setup time for test fidelity: your tests run against the actual database engine, not a mock, catching real schema and driver issues before production.
Use it for
- Integration testing a web application against a real Postgres or MySQL database without manual container management.
- Testing database migrations and schema changes against multiple database versions in parallel CI jobs.
- Validating ORM queries and raw SQL against Oracle or SQL Server in a containerized test environment.
- Testing Redis or Elasticsearch client code with a real service instance isolated per test run.
- Verifying multi-database support in a library by running the same test suite against Postgres, MySQL, and CockroachDB fixtures.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need real database testing in a containerized environment.
The low install friction, active maintenance, permissive license, and broad database support make it a solid choice for integration tests. The main gotcha is the Docker dependency—you must have Docker running, and container startup adds latency per test. For unit tests or projects that cannot use Docker, this is not the right tool.
Install
pytest-databases on PyPI
Before you install
Low friction installation with a pure Python wheel. Maintenance is active with a recent release; the package is in Beta status and depends on docker, filelock, and pytest—all stable, widely-used libraries.
Requires Docker to be installed and running on the system; the package manages database container lifecycle but does not provide Docker itself.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
Quickstart
pip install pytest-databases[postgres]
# In conftest.py:
pytest_plugins = ["pytest_databases.docker.postgres"]
# In test file:
from pytest_databases.docker.postgres import PostgresService
def test_example(postgres_service: PostgresService):
# Use postgres_service.host, .port, .user, .password, .database
Verify before relying
- Whether all listed database versions (Postgres 12–18, MySQL 5.6–8, Oracle 18c/23c, SQL Server 2022) are actively maintained in the fixture set.
- Performance characteristics and overhead of spinning up containers per test or per session.
- Whether the package handles cleanup and resource limits to prevent orphaned containers in CI/CD environments.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.9 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagesdockerfilelockpytest |
| Maintenance | Actively maintained 83 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 74,438 / month, #14,830 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy |
Evidence: pytest_databases-0.19.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “isolated test databases”
- pytest-databasesProvides pytest fixtures that spin up isolated database services in…
- testcontainers-coreProvides Docker container orchestration for functional and…
- pytest-mock-resourcesProvides pytest fixtures that spin up real database and service…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also pytest-mock-resources · pytest-pgsql · testcontainers-core · testcontainers · pytest-redis · pytest-mysql · pytest-postgresql · py-pglite · testing.common.database · testing.postgresql