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 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/).
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.
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"]
...
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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 363ea1b4666dbed9577ff06f612da65f23db4aa3bba31b20dd1d4a3027449139 |
|
MD5 | cfb20cf198e7a39a00ddae7014fd0fc4 |
|
BLAKE2b-256 | a1a7f94221d3b2b4d4a5c2c6ca02f8213536589455ba6829cff8b389d5a0c64c |
Hashes for pytest_docker_service-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1c36f9869b56e60b4c9641723e692e8b9d165ee75c65cf91b104f28b7d17ab9 |
|
MD5 | fdefca47491fb289cb32e0c863394b4b |
|
BLAKE2b-256 | 0b1185d3914fe1d5369d6815ef04ee1e6c111f1d0b112f65f364a69868530069 |