Skip to main content

pytest plugin to start docker container

Project description

image image CI


pytest-docker-service is a pytest plugin for writing integration tests based on docker containers.

The plugin provides a fixtures factory: a configurable function to register fixtures.

The package has been developed and tested with Python 3.11, and pytest version 7.4.


Install pytest-docker-service with pip.

python -m pip install pytest-docker-service


You just have to create a fixture in your or in individual test modules, using the docker_container helper. Fixture is created with the scope provided through the scope parameter. Other parameters are wrappers around the docker-py API (

import requests
from pytest_docker_service import docker_container

container = docker_container(
    ports={"80/tcp": None},

def test_status_code(container):
    port = container.port_map["80/tcp"]

    status = 200
    response = requests.get(f"{port}/status/{status}")

    assert response.status_code == status

Of course, if you want to build your own docker image, it is possible. Just set the build_path parameter pointing to the directory containing the Dockerfile.

container = docker_container(
    ports={"80/tcp": None},

def test_status_code(container):
    port = container.port_map.["5432/tcp"]


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_service-0.2.8.tar.gz (16.1 kB view hashes)

Uploaded Source

Built Distribution

pytest_docker_service-0.2.8-py3-none-any.whl (17.1 kB view hashes)

Uploaded Python 3

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