pytest-dockerc
pytest-dockerc is a plugin for pytest that provides support
for running test from Docker Compose project.
The docker-compose up -d command is executed at the beginning of the
test session and the docker-compose down command at the end. The main fixture dockerc
returns a compose.project.Project
to deal with the python docker API in your tests. Another fixture dockerc_logs is provided to enable
the logs on stdout during your tests execution.
This plugin provides a way to use as far as possible the same environment for development, test, integration and production phases. You test and deploy the same artifact in order to avoid side effects in production.
Install
pip install pytest-dockerc
Getting started
Below a basic example, you can also refer to a full example with an http server.
worktree
├── docker-compose.yml
└── tests
├── conftest.py
└── test_example.py
docker-compose.yml
version: "3.6"
services:
python:
image: python:3-alpine
test_example.py
def test_example(dockerc):
assert len(dockerc.containers()) == 1
container = dockerc.containers()[0]
assert container.is_running is True
assert container.labels["com.docker.compose.service"] == "python"
Available options
Some options are available to update the default behavior of the plugin.
dockerc:
--dockerc-norun disable the run and stop commands of docker-compose
--dockerc-attach-network
attach the pytest container to the docker-compose
network,only if pytest is started inside a container
--dockerc-filepath=DOCKERC_FILEPATH
set the Compose file path
--dockerc-projectdir=DOCKERC_PROJECTDIR
set the working directory of the Compose project
--dockerc-projectname=DOCKERC_PROJECTNAME
set project name of the Compose project
--dockerc-build build images before starting containers
--dockerc-services=DOCKERC_SERVICES
select services to run
Run tests without up and down command of docker-compose
Running the full docker-compose project can take time, if you loads several services. It is useful to run the test on a running instance. That method is recommended when you write a new test.
First start your docker compose like usual:
docker-compose up
Then run your tests with the --dockerc-norun, that will skip the up and down command:
pytest --dockerc-norun
Below the docker-compose output after 2 runs of the test tests/test_fixtures::test_basic_workflow,
which performs a GET request.
Creating network "pytest-dockerc_default" with the default driver
Creating pytest-dockerc_http_1 ... done
Attaching to pytest-dockerc_http_1
http_1 | 192.168.32.1 - - [24/Dec/2018:08:48:21 +0000] "GET / HTTP/1.1" 200 612 "-" "python-requests/2.20.0" "-"
http_1 | 192.168.32.1 - - [24/Dec/2018:08:48:22 +0000] "GET / HTTP/1.1" 200 612 "-" "python-requests/2.20.0" "-"
Metadata
Release files for pytest-dockerc 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| pytest-dockerc-1.0.8.tar.gz | 8.4 kB | Without provenance | Details for pytest-dockerc-1.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_dockerc-1.0.8-py3-none-any.whl | Python 3 | none | any | Details for pytest_dockerc-1.0.8-py3-none-any.whl |
Total release size: 15.8 kB
Release files / pytest-dockerc-1.0.8.tar.gz
| Download URL | pytest-dockerc-1.0.8.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6273e244175a4394683a06ef060d0ba5e85e1c88b779776f11f767ed9f9f1b0
|
|
BLAKE2b-256 checksum How to use checksums |
57654745bf952b23d9a20bce36ab7d711c0457a637fa14a55cdfaac8c6f48dc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
|
Release files / pytest_dockerc-1.0.8-py3-none-any.whl
| Download URL | pytest_dockerc-1.0.8-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f03405384db981e30ad6f391337f210903c9e37818cf14a68af0d4064c91bcf4
|
|
BLAKE2b-256 checksum How to use checksums |
c7fae54b00bf7ac8010114229e89eee1b4b93515d90996e4724ece5081310f45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
|
Security for pytest-dockerc 1.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.