pytest-container
Pytest fixtures for writing container based tests
What it is and what it does
pytest-container is a pytest plugin that wraps the complexity of container-based testing. It provides fixtures that automatically pull, launch, and tear down container images, bind exposed ports to free host ports, mount volumes, and wait for containers to become healthy—all without you writing boilerplate. Your test functions receive a testinfra connection object to run assertions inside the running container (checking for files, installed packages, services, etc.), turning container image validation into ordinary pytest tests.
The plugin handles the tedious infrastructure work: finding free ports, managing temporary directories for volumes, cleaning up after tests, orchestrating dependent container builds in the right order, and supporting parallel test execution. It's designed for functional testing of OS container images and verifying that software runs correctly across multiple operating systems or distributions.
Use it for:
- Verify that a Dockerfile produces a working image by testing file presence, package installation, and service startup inside the container.
- Run the same test suite against multiple OS container images to ensure cross-platform compatibility.
- Test multi-container setups by creating and destroying podman pods within pytest fixtures.
- Validate container port bindings and volume mounts by asserting on container state from the host.
- Integrate container image validation into CI/CD pipelines as part of a standard pytest test run.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that automates container testing by managing container lifecycle, port binding, volume mounting, and health checks, letting you write tests against container images using testinfra.
Yes, if you need to test container images programmatically. The plugin is actively maintained, has low install friction, and solves a real problem—automating container lifecycle management in tests. The LGPL-2.1-or-later license requires source distribution if you modify and redistribute, which is typical for testing tools. No known security vulnerabilities. Suitable for teams building and validating container images as part of their development workflow.
Install
pytest-container on PyPI
pip
pip install pytest-containeruv
uv add pytest-containerpoetry
poetry add pytest-containerInstalling pytest-container
Before you install
Low install friction with a pure-Python wheel distribution. Active maintenance with a recent commit on 2026-03-02 and regular releases; the project has been stable since its first release in 2021-11-19.
License in practice
Licensed under LGPL-2.1-or-later (copyleft). You must distribute source code and license terms with any derivative work, and any modifications must be released under the same or compatible license.
Quickstart
pip install pytest-container
from pytest_container import Container
import pytest
TW = Container(url="registry.opensuse.org/opensuse/tumbleweed:latest")
@pytest.mark.parametrize("container", [TW], indirect=["container"])
def test_etc_os_release_present(container):
assert container.connection.file("/etc/os-release").exists
Requires a container runtime (Docker or Podman) installed and running on the host system.
Verify before relying
- Whether the package supports both Docker and Podman equally, or if one is preferred.
- Specific Python version compatibility (requires_python is unspecified in metadata).
- Performance characteristics when running tests in parallel with pytest-xdist.
Package facts
| License | LGPL-2.1-or-later (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — pytest, pytest-testinfra, dataclasses, typing-extensions, cached-property, filelock, deprecation |
| Maintenance | actively maintained — 410 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 167,086/month — #10,479 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_container-0.4.4-py3-none-any.whl
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-docker-toolsProvides pytest fixture factories for…
permissive · top 5,000 on PyPI
tox-dockerA tox plugin that manages Docker container…
permissive · top 15,000 on PyPI
pytest-datadirA pytest plugin that provides fixtures for…
permissive · top 5,000 on PyPI
pytest-dockerpytest-docker provides pytest fixtures that…
permissive · top 5,000 on PyPI
pytest-testinfraA pytest plugin that lets you write Python unit…
permissive · top 5,000 on PyPI
container-inspectorAnalyzes Docker images, containers, and virtual…
permissive · top 15,000 on PyPI
testinfraTestinfra lets you write Python unit tests that…
permissive · top 15,000 on PyPI
testcontainers-coreProvides Docker container orchestration for…
unclear · top 15,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