skillfed

pytest-docker-tools

Docker integration tests for pytest

pytest-docker-tools v3.1.10 1.7M downloads/30d#3,603 on PyPI102
Permissive license Apache-2.0 Active released

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-tools

uv

uv add pytest-docker-tools

poetry

poetry add pytest-docker-tools

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.9Topic :: Software Development :: Testing

Tags

docker pytest fixturescontainer integration testingdocker-compose pytestsmoke testing docker imagespytest docker containersdocker test environment automationcontainer fixture factories
docker-testingpytest-pluginintegration-testing

More Testing packages