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"]
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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d166acb97078847752e6245f26155112d6b1e4f9a5ef43266898324e340d5b78 |
|
MD5 | e0e0381118893469cb75e0fd709af138 |
|
BLAKE2b-256 | 54666b729e9532476bb1dc9951c986a37d8f04f1a6e970441958a1dba191fc2d |
Hashes for pytest_docker_service-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14d249d77e1f19c35d6f4eaaad927719facf7596013f363f12078d50f4d404e2 |
|
MD5 | ff389c7938c52728f120baa08f975910 |
|
BLAKE2b-256 | e5dae08cbe07484fe487e01f9fdc97605be08a9aaff7f4ed539426c37e3c5b70 |