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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_container-0.1.1.tar.gz (36.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_container-0.1.1-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_container-0.1.1.tar.gz.

File metadata

  • Download URL: pytest_container-0.1.1.tar.gz
  • Upload date:
  • Size: 36.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/6.1.18-200.fc37.x86_64

File hashes

Hashes for pytest_container-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c1556c34fde2b6b68f86ce4af16194d7801b6a2e690ad326eaeb1c54c52cf02e
MD5 c03d0571281e9d4551acac924f7a4cf8
BLAKE2b-256 703b18c417b058e8f1733d7be64fa050c7ed40f7ab87fdb56b92b601d454eea1

See more details on using hashes here.

File details

Details for the file pytest_container-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_container-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/6.1.18-200.fc37.x86_64

File hashes

Hashes for pytest_container-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df182233775c87a342e1673159eece40410a99569db6199f53af42719050ec41
MD5 7109817b98001dd4d03fffb755838029
BLAKE2b-256 02f2e8471edab8c3240120a3723c98190a284d18f6374799aca619980ed82478

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

This release

0.1.1 This release

2 files

0.0.2

2 files

0.0.1

2 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