Skip to main content

Run, manage and stop Docker Compose project from Docker API

Project description


pytest-dockerc is a plugin for pytest that provides support for running test from Docker Compose project. The docker-compose up -d command is executed at the beginning of the test session and the docker-compose down command at the end. The main fixture dockerc returns a compose.project.Project to deal with the python docker API in your tests. Another fixture dockerc_logs is provided to enable the logs on stdout during your tests execution.


pip install pytest-dockerc

Getting started

Below a basic example, you can also refer to a full example with an http server.


├── docker-compose.yml
└── tests


version: "3.6"

    image: python:3-alpine

def test_example(dockerc):
    assert len(dockerc.containers()) == 1
    container = dockerc.containers()[0]
    assert container.is_running is True
    assert container.labels["com.docker.compose.service"] == "python"

Available options

Some options are available with the behavior of the plugin.

  --dockerc-norun       disable the run and stop commands of docker-compose.
                        set the Compose file path
                        set the working directory of the Compose project
  --dockerc-build       build images before starting containers
                        select services to run

Run tests without up and down command of docker-compose

Running the full docker-compose project can take time, if you loads several services. It is useful to run the test on a running instance. That method is recommended when you write a new test.

First start your docker compose like usual:

docker-compose up

Then run your tests with the --dockerc-norun, that will skip the up and down command:

pytest --dockerc-norun

Below the docker-compose output after 2 runs of the test tests/test_fixtures::test_basic_workflow, which performs a GET request.

Creating network "pytest-dockerc_default" with the default driver
Creating pytest-dockerc_http_1 ... done
Attaching to pytest-dockerc_http_1
http_1  | - - [24/Dec/2018:08:48:21 +0000] "GET / HTTP/1.1" 200 612 "-" "python-requests/2.20.0" "-"
http_1  | - - [24/Dec/2018:08:48:22 +0000] "GET / HTTP/1.1" 200 612 "-" "python-requests/2.20.0" "-"

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytest-dockerc, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size pytest_dockerc-1.0.2-py3-none-any.whl (5.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pytest-dockerc-1.0.2.tar.gz (6.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page