Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.67 KB

README.rst

File metadata and controls

55 lines (42 loc) · 1.67 KB

pytest-dockerctl

Docker control integrated with pytest for system testing.

pytest-dockerctl is a pytest plugin for managing all things docker using the docker-py API.

Install

For now install from this repo:

pip install git+git://github.com/tgoodlet/pytest-dockerctl.git

Usage

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.