Docker control integrated with pytest
for system testing.
pytest-dockerctl
is a pytest plugin for managing all things
docker using the docker-py API.
For now install from this repo:
pip install git+git://github.com/tgoodlet/pytest-dockerctl.git
Provides a dockerctl
fixture for spinning up and tearing down containers:
import pytest
import subprocess
@pytest.fixture
def server_addrs(dockerctl):
addrs = []
# spin up 4 of the same container
with dockerctl.run(
'docker_repo/my_image'
volumes={'/local/config/path': {'bind': '/etc/server/config'}},
num=4,
) as containers:
for container in containers:
addrs.append(container.attrs['NetworkSettings']['IPAddress'])
yield addrs
# all containers are stopped and removed when the context manager exits
def test_startup_ping(server_addrs):
for addr in server_addrs:
subprocess.check_call("ping -c 1 {}".format(addr))
The dockerctl
object is a DockerCtl
instance which (for now) is
just a simple wrapper around a docker-py DockerClient. You can access
the underlying client via dockerctl.client
.