Skip to main content

Pytest container

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.2.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.2.0
File Size Uploaded Provenance Actions
pytest_container-0.2.0.tar.gz 37.6 kB Without provenance Details for pytest_container-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 78.9 kB

Release files / pytest_container-0.2.0.tar.gz

Download URL pytest_container-0.2.0.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
39a25a7af0333b2c52ac8ba618155fee75192646991540b0ee9201bbf5a65e58
BLAKE2b-256 checksum
How to use checksums
b1b02e665171520c607759e9f3054db7b19a14742f034f5e35c29ac428d91fdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.11.3 Linux/6.3.6-200.fc38.x86_64

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

Download URL pytest_container-0.2.0-py3-none-any.whl
Size 41.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cfde475820aba8f4241df40cfeab59a87376e7e1b3714973f5f47c24387a8aa
BLAKE2b-256 checksum
How to use checksums
908687d1cf550fb2000bf1001cc0403aff83775982f3142d806d62b71e4c3a4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.11.3 Linux/6.3.6-200.fc38.x86_64

Security for pytest-container 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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