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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cca0a47850a04186f66ba13d130fbba0609c5b2daddc43942ee56ef08de3587 |
|
MD5 | 1b0cdc4b168c3efbd76487ad46e4c6b6 |
|
BLAKE2b-256 | d9514953ec9010d78238847e1f901e8f111382886a6e75312cb8124588db8ebd |
Hashes for pytest_docker_service-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77ee7d517f3fee5c2c80f1f44948f134d11a92b414a4f7d1297f5963c6417370 |
|
MD5 | af26957627d6dd77916d63923bdfa7af |
|
BLAKE2b-256 | 1c80e62dc8941236eb870b533afa78d9343f03f57d6750fddb036b03e3e94ac4 |