Skip to main content

UNKNOWN

Project description

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.

Usage

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 (
    ConnectionError,
)

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

@pytest.fixture(scope='session')
def some_http_service(docker_ip, docker_services):
    """Ensure that "some service" is up and responsive."""
    url = 'http://' % (
        docker_ip,
        docker_services.port_for('abc', 123),
    )
    docker_services.wait_until_responsive(
       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)
    response.raise_for_status()

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 conftest.py file:

import pytest

@pytest.fixture(scope='session')
def docker_compose_file(pytestconfig):
    return os.path.join(
        str(pytestconfig.rootdir),
        'mycustomdir'
        'docker-compose.yml'
    )

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

@pytest.fixture(scope='session')
def docker_allow_fallback():
    return True

Changelog

Version 0.3.0

  • Added --build option to docker-compose up command to automatically rebuild local containers.

Contributing

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.

Source Distribution

pytest-docker-0.3.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distributions

pytest_docker-0.3.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

pytest_docker-0.3.0-py2-none-any.whl (4.3 kB view details)

Uploaded Python 2

File details

Details for the file pytest-docker-0.3.0.tar.gz.

File metadata

File hashes

Hashes for pytest-docker-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fd623876e2bc1e555f86d6e5259d68514c4cf416359329b2103d8d61500ee2f7
MD5 5b5a1a8648f067d745f9a85efafcc04b
BLAKE2b-256 fc39285534b48a059d650935aebef10b79d626847e8788556a81958f646ce9c7

See more details on using hashes here.

File details

Details for the file pytest_docker-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_docker-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d86fcfeb7ab48f45bdf9656791f22b76bea7602ad4e83b82cabfcfe785c2c00
MD5 5ec7c26170b049c357dce76bd978f4f4
BLAKE2b-256 a70017610dfa6501a533fd78d11e1fd13c62198e2fbcbbca2ac7fa5f56100d5d

See more details on using hashes here.

File details

Details for the file pytest_docker-0.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for pytest_docker-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 a1debc7e8ae715b454e90b142f0f4105b815ae15bed36b31b2acd2a7995b1f26
MD5 405bc489791491ac03a21a08f421b88b
BLAKE2b-256 094672b44d399609406931eef80894d22c835d943a8d3339e55574255674f8c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page