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
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
Hashes for pytest_container-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d37c9002367be2b57090efbe23f77cbd1ca1f6f9b53381d9a56ff7aa10e4e3b2 |
|
MD5 | 0cccce484c80f9dfcdf8a841f1a20861 |
|
BLAKE2b-256 | edf430a29dd6a21f74454bc8cb2db8b27efb1d1ad713302bcfab035d1ba71184 |