pytest-container
Pytest fixtures for writing container based tests
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires a container runtime (Docker or Podman) installed and running on the host system.
- 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 · maintenance · safety
LGPL-2.1-or-later (copyleft) — 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.
last release 2025-06-30 (410 days) · last repo commit 2026-03-02 · 44 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 167,086 downloads/mo, #10,479 on PyPI
Alternatives
Verify before relying
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- 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.
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 on it.
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
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.
Requires a container runtime (Docker or Podman) installed and running on the host system.
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
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 packagespytestpytest-testinfradataclassestyping-extensionscached-propertyfilelockdeprecation |
| 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 |
| Classifiers | Development Status :: 4 - BetaFramework :: PytestIntended Audience :: DevelopersLicense :: OSI ApprovedLicense :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)Topic :: Software Development :: Quality AssuranceTopic :: Software Development :: Testing |
Evidence: pytest_container-0.4.4-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 › “pytest container testing”
- pytest-containerA pytest plugin that automates container testing by managing…
- pytest-docker-toolsProvides pytest fixture factories for declaratively defining…
- pytest-dockerpytest-docker provides pytest fixtures that automatically spin up and…
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-docker-tools · tox-docker · pytest-datadir · pytest-docker · pytest-testinfra · container-inspector · testinfra · testcontainers-core · pytest-mock-resources · pytest-redis