--- id: pytest-docker version: "3.2.5" license: MIT license_treatment: permissive maintenance: aging --- # pytest-docker — Simple pytest fixtures for Docker and Docker Compose based tests License: permissive · Maintenance: aging · Downloads: 2.4M/mo ## What it is and what it does pytest-docker is a pytest plugin that manages Docker containers as test fixtures. It reads a docker-compose.yml file, starts all defined services before tests run, and tears them down afterward—all handled transparently by pytest's fixture system. You define your services once in compose YAML, then inject a docker_services fixture into your tests to query container ports, wait for readiness, and interact with running services. The plugin handles the boilerplate of container lifecycle management, port mapping discovery, and health checks. It supports both Docker Compose V2 (default, via the docker compose command) and V1 (via optional extra or custom fixture override). Tests run against real containerized services rather than mocks, making integration tests more realistic and catching issues that unit tests miss. Use it for: - Write integration tests against a real database running in a container without manual docker-compose commands. - Test HTTP services by spinning up a containerized service and making requests to it from pytest. - Validate multi-service interactions in a single test run using docker-compose to define the stack. - Debug test failures in an IDE by pinning the compose project name and reusing containers across debug sessions. - Use multiple docker-compose files to compose different service stacks for different test scenarios. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. pytest-docker provides pytest fixtures that automatically spin up and tear down Docker containers from a docker-compose.yml file for the duration of your test session, eliminating manual container lifecycle management. Yes. pytest-docker is a well-established plugin (in top 5000 PyPI packages by downloads) with low install friction, permissive licensing, no known vulnerabilities, and active maintenance. It solves a real problem—automating container lifecycle for integration tests—cleanly. Install it if your test suite needs real containerized services rather than mocks or if you're already using docker-compose for local development. ## Install pip install pytest-docker uv add pytest-docker poetry add pytest-docker ## Installing pytest-docker Before you install: Low friction: pure Python wheel with only pytest and attrs as runtime dependencies. Maintenance status is aging—last release 275 days ago—but the repository remains active with recent commits and no archived status. License in practice: MIT license is permissive; safe for commercial and closed-source use without reciprocal obligations. Quickstart: # Install pip install pytest-docker # In conftest.py or test file: import pytest @pytest.fixture(scope="session") def docker_compose_file(pytestconfig): return "docker-compose.yml" # In test: def test_service(docker_services): port = docker_services.port_for("myservice", 80) # Use port to connect to containerized service Docker and Docker Compose V2 (or V1 via optional extra) must be installed and available in PATH on the test environment. Verify before relying: - Whether Docker and Docker Compose V2 (or V1 via optional extra) are assumed to be pre-installed on the test environment. - Performance characteristics when managing many containers or long-running test suites. - Compatibility with Docker Desktop on Windows and macOS beyond the stated OS classifiers. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 2.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest docker fixtures, docker compose integration tests, containerized pytest tests, docker test automation, pytest docker compose plugin, container-based testing, docker fixtures pytest, docker, integration-testing, fixtures [View on SkillFed](https://skillfed.io/packages/pytest-docker) · [View on PyPI](https://pypi.org/project/pytest-docker/)