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.11, and pytest version 7.4.
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.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3ba91c2213120ce9d2a3ebd5a5ea56c2ccc8039a5159664fa133924eb10883a |
|
MD5 | 0f36c7663be5e73711ff4edb316125ed |
|
BLAKE2b-256 | 4683598b2bc1de3431ca70a60fd81955dce2eafd00ae311a9e120007f42d110c |
Hashes for pytest_docker_service-0.2.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ed9d0309873754d46d9ce91e561aecec41f97d11bc8538e1419d0c31fec1ae1 |
|
MD5 | 137c49329ecbe808d4a836569a9e9ddc |
|
BLAKE2b-256 | 2de4f780c581cae10d2651bf5e5bd9560235014774bea1956775a63f18117936 |