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"]
...
Release files for pytest-docker-service 0.2.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_docker_service-0.2.8.tar.gz | 16.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_docker_service-0.2.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.3 kB
Release files / pytest_docker_service-0.2.8.tar.gz
| Download URL | pytest_docker_service-0.2.8.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46b5a8be72b88539b4b84b5e26e36f96da017d58d2af2375e887c5246155a025
|
|
BLAKE2b-256 checksum How to use checksums |
bb0ed44571ee50d4b3ac8b95504c294c315f76c7239e3353e0d5c19bf4166af1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / pytest_docker_service-0.2.8-py3-none-any.whl
| Download URL | pytest_docker_service-0.2.8-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ffdd602c654d06c70be64c264930983724455b22013b90ecf2723ad90c7016e3
|
|
BLAKE2b-256 checksum How to use checksums |
89d470f6d4a2ec7483b9626018566a69543b3ca79f336072f1d90d09b133bb65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|