A pytest plugin for docker and kubernetes fixtures. The plugin provides a framework for testing docker container images.
This plugin enables you to test code run in containers that relies on docker resources (container, volume, secret, network, ....). It allows you to specify fixtures for docker resources.
The main interface provided by this plugin is a set of fixtures and 'fixture factories'.
- orchestrate fixtures using docker compose
- orchestrate fixtures using docker swarm
- orchestrate fixtures using kubernetes
- orchestrate fixtures using maestro-ng
- orchestrate fixtures using low level docker and kubernetes interfaces
- docker (Tested on 18.06)
- Python (Tested on 3.6)
- pytest (Tested on 3.6.4)
- docker-py (Tested on 3.5.0)
- docker-compose (Tested on 1.22.0)
- maestro-ng (Tested on 0.5.4)
- kubernetes (Tested on 1.10.3)
You can install "pytest-containers" via pip from PyPI:
pip install pytest-containers
Or include it as a dependency on setup.py
or a requirements.txt
file, whatever you prefer.
The following tests demonstrate how to use the fixtures provided by this plugin.
# test_container.py
def test_is_healthy(container):
assert container.status == 'running'
...
The docker_client fixture returns an instance of the official docker client.
def test_docker_version(docker_client):
res = docker_client.version()
assert 'GoVersion' in res
assert 'Version' in res
The container fixture returns an instance of Container.
def test_container(container):
assert container.status == 'running'
The client container fixture returns an instance of Container connected to another container.
def test_client_container(container, client_container):
assert container.status == 'running'
assert client_container.status == 'running'
The container fixuture returns an instance of Network.
def test_default_network(network):
assert network.name == 'bridge'
assert network.attrs['Options']['com.docker.network.bridge.default_bridge' == 'true'
The container fixuture returns an instance of Image.
def test_image(image):
assert image is not None
Read the full documentation to see everything you can do.
Contributions are very welcome. Tests can be run with tox
, please ensure
the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the Apache Software License 2.0 license, "pytest-containers" is free and open source software
If you encounter any problems, please file an issue
along with a detailed description.