pytest plugin to start docker container
Project description
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 confest.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/).
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"]
host = container["host"]
status = 200
response = requests.get(f"http://{host}:{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(
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"]
host = container["host"]
...
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
Built Distribution
Hashes for pytest-docker-service-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f35e27b380f548d40b271f03cbf66dd57073b20e5a5782f3cccb6f837dc66f5 |
|
MD5 | 1eb45a5a67322d63ce1fc886bb3712df |
|
BLAKE2b-256 | 990e17ed962d5d67276da583d32d50ed913a95a9c77bcdc55ac17fdb09b13b40 |
Hashes for pytest_docker_service-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b88936a90924b8db0f290edde3e458e2a23d9d7163cadc75e75de2b3fc4ecf2 |
|
MD5 | ccc998dd133c3449e6fd46aa6bbc73eb |
|
BLAKE2b-256 | d5a1b80913152e2b2ee64ac7a99b9f10e58392ad2623b32decb48e5386e59dfe |