Metadata-Version: 2.1
Name: pytest-docker-service
Version: 0.2.4
Summary: pytest plugin to start docker container
Home-page: https://github.com/ClementDelgrange/pytest-docker-service
License: GNU GPL v3
Keywords: pytest,docker,devops
Author: Clément Delgrange
Requires-Python: >=3.8.0,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Testing
Requires-Dist: docker (>=6.0.0)
Requires-Dist: pytest (>=7.1.3)
Requires-Dist: tenacity (>=8.1.0)
Project-URL: Repository, https://github.com/ClementDelgrange/pytest-docker-service
Description-Content-Type: text/markdown

[![Python package](https://github.com/ClementDelgrange/pytest-docker-service/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/ClementDelgrange/pytest-docker-service/actions/workflows/ci.yaml)

# pytest-docker-service

`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.10, and pytest version 6.2.

## Installation
Install `pytest-docker-service` with `pip`.

```
python -m pip install pytest-docker-service
```

## Usage
You just have to create a fixture in your `conftest.py` 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 (https://docker-py.readthedocs.io/en/stable/).

```python
import requests
from pytest_docker_service import docker_container

container = docker_container(
    scope="session",
    image_name="kennethreitz/httpbin",
    ports={"80/tcp": None},
)


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

    status = 200
    response = requests.get(f"http://127.0.0.1:{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.
```python
container = docker_container(
    scope="session",
    image_name="my-image",
    build_path="path/to/dockerfile/directory",
    ports={"80/tcp": None},
)


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

    ...

```

