Skip to main content


Project description


Simple py.test fixtures for writing integration tests based on Docker containers. Specify all containers you need and pytest-docker will use Docker Compose to spin them up for the duration of your test suite.


Here is the basic recipe for writing a test that depends on a service that responds over HTTP:

import pytest
import requests

from requests.exceptions import (

def is_responsive(url):
    """Check if something responds to ``url``."""
        response = requests.get(url)
        if response.status_code == 200:
            return True
    except ConnectionError:
        return False

def some_http_service(docker_ip, docker_services):
    """Ensure that "some service" is up and responsive."""
    url = 'http://' % (
        docker_services.port_for('abc', 123),
       timeout=30.0, pause=0.1,
       check=lambda: is_responsive(url)
    return url

def test_something(some_service):
    """Sample test."""
    response = requests.get(some_service)

By default this plugin will try to open docker-compose.yml in your tests directory. If you need to use a custom location, override the docker_compose_file fixture inside your file:

import pytest

def docker_compose_file(pytestconfig):
    return os.path.join(

You can allow this plugin to run your tests when Docker is not available. It will use the container port and localhost instead:

def docker_allow_fallback():
    return True


This py.test plug-in and its source code are made available to your under and MIT license. It is safe to use in commercial and closed-source applications. Read the license for details!

Found a bug? Think a new feature would make this plug-in more practical? No one is paid to support this software, but we welcome pull requests!

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-docker, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size pytest_docker-0.2.0-py2-none-any.whl (4.3 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size pytest_docker-0.2.0-py3-none-any.whl (4.3 kB) File type Wheel Python version 3.5 Upload date Hashes View
Filename, size pytest-docker-0.2.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page