Pytest fixtures for writing container based tests
Project description
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
Run functional tests on operating system container images
Verify your software on multiple operating systems
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_container-0.4.4.tar.gz.
File metadata
- Download URL: pytest_container-0.4.4.tar.gz
- Upload date:
- Size: 65.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e19c7b6004e03e8977901a3761a235396cb656ebe671ca15b52702736020f328
|
|
| MD5 |
07ac34e3efc0423a4c7643b4508a6156
|
|
| BLAKE2b-256 |
1b5c5f555593120d923caec884aa88f0c0aeb3ccf1007475cdc04fd306c94642
|
Provenance
The following attestation bundles were made for pytest_container-0.4.4.tar.gz:
Publisher:
release.yml on dcermak/pytest_container
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_container-0.4.4.tar.gz -
Subject digest:
e19c7b6004e03e8977901a3761a235396cb656ebe671ca15b52702736020f328 - Sigstore transparency entry: 256130433
- Sigstore integration time:
-
Permalink:
dcermak/pytest_container@a465c0f374cdec2290a2a958e48bfd4e12445fbd -
Branch / Tag:
refs/tags/0.4.4 - Owner: https://github.com/dcermak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a465c0f374cdec2290a2a958e48bfd4e12445fbd -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_container-0.4.4-py3-none-any.whl.
File metadata
- Download URL: pytest_container-0.4.4-py3-none-any.whl
- Upload date:
- Size: 75.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afbf03fc308e6c38c6ee4b6180dfa76b442553f6b0777e57ffaf6d8ee48a1407
|
|
| MD5 |
08d47b77a0c8d953c818bfac923de1ff
|
|
| BLAKE2b-256 |
ddeeed49df2a028717a099663aedd340d62031ee0a1a4ad75ff96fef4a742ef5
|
Provenance
The following attestation bundles were made for pytest_container-0.4.4-py3-none-any.whl:
Publisher:
release.yml on dcermak/pytest_container
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_container-0.4.4-py3-none-any.whl -
Subject digest:
afbf03fc308e6c38c6ee4b6180dfa76b442553f6b0777e57ffaf6d8ee48a1407 - Sigstore transparency entry: 256130446
- Sigstore integration time:
-
Permalink:
dcermak/pytest_container@a465c0f374cdec2290a2a958e48bfd4e12445fbd -
Branch / Tag:
refs/tags/0.4.4 - Owner: https://github.com/dcermak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a465c0f374cdec2290a2a958e48bfd4e12445fbd -
Trigger Event:
push
-
Statement type: