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

Metadata

Release files for pytest-container 0.3.0

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.3.0
File Size Uploaded
pytest_container-0.3.0.tar.gz 37.8 kB Details

Built distribution (wheel)

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

Total release size: 79.5 kB

Release files / pytest_container-0.3.0.tar.gz

Download URL pytest_container-0.3.0.tar.gz
Size 37.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3da6c6ccc4bdc2ea53d623e57ba9cb1900fb070346605a7d89b83c06309f4873
BLAKE2b-256 checksum
How to use checksums
d108e6422bb5fd2773861b263263928284321c9e52bb322622a9701cf98b4299
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.5

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

Download URL pytest_container-0.3.0-py3-none-any.whl
Size 41.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f50315a69163cf1475a6a62a662a3c99b5c2c1da9283b87b7aecc0c5961d92e9
BLAKE2b-256 checksum
How to use checksums
9947ca749aa733509bbdb159a52ff8e2bc1e0d58d8c1ccd34c09d47651c6047c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

0.4.4

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

This release

0.3.0 This release

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