pytest-docker-tools
Docker integration tests for pytest
What it is and what it does
pytest-docker-tools is a fixture factory library that lets you define Docker-based test environments declaratively in pytest, similar to docker-compose.yml syntax. Instead of writing boilerplate code to spin up containers for each test, you define fixtures once in conftest.py and inject them into tests; the library handles creation, teardown, and dependency resolution automatically. It supports fixture scoping (session, module, function), automatic port mapping, environment variable injection, and container restart operations.
The library is built on pytest and docker as its only runtime dependencies, making installation straightforward. It's designed for smoke testing Docker images and integration testing microservices, with explicit support for parallel test execution via pytest-xdist. Fixtures can be overridden per test module, and the library captures Docker logs on test failure for debugging.
Use it for:
- Smoke-test a freshly built Docker image before release to verify it starts and responds correctly.
- Integration test a microservice by spinning up dependent containers (database, cache, mock DNS) per test with automatic cleanup.
- Run parallel integration tests across multiple CPU cores using pytest-xdist, with automatic port and resource name collision avoidance.
- Reuse long-lived containers (session scope) across multiple test modules while recreating module-scoped resources between modules.
- Test container restart behavior and recovery without manual container lifecycle management in test code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides pytest fixture factories for declaratively defining Docker-based test environments, automating container creation, teardown, and dependency resolution across test scopes.
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a real problem—eliminating boilerplate for Docker-based testing. It's well-suited for teams running integration or smoke tests against containerized services. The permissive Apache-2.0 license poses no restriction. Install it if you're writing tests that need Docker containers.
Install
pytest-docker-tools on PyPI
pip
pip install pytest-docker-toolsuv
uv add pytest-docker-toolspoetry
poetry add pytest-docker-toolsInstalling pytest-docker-tools
Before you install
Low friction: pure Python wheel with only pytest and docker as runtime dependencies. Active maintenance with a release 24 days ago; repository shows 102 stars and no archived status.
License in practice
Apache-2.0 is permissive; you can use this in commercial projects and modify it freely, with minimal restrictions beyond preserving license notices.
Quickstart
pip install pytest-docker-tools
# In conftest.py
from pytest_docker_tools import container, fetch
my_image = fetch(repository='redis:latest')
my_container = container(image='{my_image.id}', ports={'11211/tcp': None})
# In test_example.py
def test_redis(my_container):
port = my_container.ports['11211/tcp'][0]
# connect and test
Requires Docker daemon running and accessible; pytest must be installed.
Verify before relying
- Whether fixture scopes (session, module, function) work as documented with pytest-xdist parallelism.
- Performance characteristics when managing many concurrent containers under xdist.
- Compatibility with Docker Desktop vs. other Docker installations.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (<4.0.0,>=3.9.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pytest, docker |
| Maintenance | actively maintained — 24 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,737,976/month — #3,603 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_docker_tools-3.1.10-py2.py3-none-any.whl
Keywords: devops, docker, pytest
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-containerA pytest plugin that automates container…
copyleft · top 15,000 on PyPI
pytest-dockerpytest-docker provides pytest fixtures that…
permissive · top 5,000 on PyPI
pytest-factoryboyIntegrates factory_boy with pytest to register…
permissive · top 5,000 on PyPI
pytest-mock-resourcesProvides pytest fixtures that spin up real…
permissive · top 15,000 on PyPI
pytest-redisA pytest plugin that provides fixtures for…
copyleft · top 15,000 on PyPI
pytest-postgresqlA pytest plugin that provides fixtures to…
copyleft · top 5,000 on PyPI
pytest-rabbitmqA pytest plugin that provides fixtures to start…
copyleft · top 15,000 on PyPI
pytest-mysqlA pytest plugin that provides MySQL and MariaDB…
copyleft · top 15,000 on PyPI
pytest-databasesProvides pytest fixtures that spin up isolated…
permissive · top 15,000 on PyPI
pytest-shutilProvides pytest fixtures and utilities for…
permissive · top 15,000 on PyPI