Skip to main content
https://github.com/dcermak/pytest_container/actions/workflows/ci.yml/badge.svg https://github.com/dcermak/pytest_container/actions/workflows/codeql-analysis.yml/badge.svg https://codecov.io/gh/dcermak/pytest_container/branch/main/graph/badge.svg?token=D16Q2PGL67 https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdcermak%2Fpytest_container.svg?type=shield PyPI

Find the latest documentation on dcermak.github.io/pytest_container.

pytest_container is a pytest plugin to test container images via pytest fixtures and testinfra. It takes care of all the boring tasks, like spinning up containers, finding free ports and cleaning up after tests, and allows you to focus on implementing the actual tests.

The plugin automates the following tasks:

  • pull, launch, and stop containers

  • build containers using a Dockerfile

  • wait for containers to become healthy before executing tests

  • bind exposed container ports to free ports on the host

  • mount volumes via temporary directories

  • parallel test execution through pytest-xdist

  • build dependent container images in the correct order

  • run the same test on as many container images as necessary

  • create, launch and destroy podman pods

pytest_container provides four fixtures that give you everything you need for testing containers. Spinning up a container image can be as simple as instantiating a Container and parametrizing a test function with the container fixture:

TW = Container(url="registry.opensuse.org/opensuse/tumbleweed:latest")

@pytest.mark.parametrize("container", [TW], indirect=["container"])
def test_etc_os_release_present(container: ContainerData):
    assert container.connection.file("/etc/os-release").exists

The fixture automatically pulls and spins up the container, stops it and removes it after the test is completed. Your test function receives an instance of ContainerData with the ContainerData.connection attribute. The ContainerData.connection attribute is a testinfra connection object. It can be used to run basic tests inside the container itself. For example, you can check whether files are present, packages are installed, etc.

Use cases

  1. Run functional tests on operating system container images

  2. Verify your software on multiple operating systems

Release files for pytest-container 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-container 0.4.4
File Size Uploaded
pytest_container-0.4.4.tar.gz 65.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-container 0.4.4
File Interpreter ABI Platform
pytest_container-0.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 141.4 kB

Release files / pytest_container-0.4.4.tar.gz

Download URL pytest_container-0.4.4.tar.gz
Size 65.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e19c7b6004e03e8977901a3761a235396cb656ebe671ca15b52702736020f328
BLAKE2b-256 checksum
How to use checksums
1b5c5f555593120d923caec884aa88f0c0aeb3ccf1007475cdc04fd306c94642
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 30, 2025.

Transparency log

Release files / pytest_container-0.4.4-py3-none-any.whl

Download URL pytest_container-0.4.4-py3-none-any.whl
Size 75.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afbf03fc308e6c38c6ee4b6180dfa76b442553f6b0777e57ffaf6d8ee48a1407
BLAKE2b-256 checksum
How to use checksums
ddeeed49df2a028717a099663aedd340d62031ee0a1a4ad75ff96fef4a742ef5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 30, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page