Docker-based integration tests
Project description
Description
Simple py.test fixtures for writing integration tests based on Docker containers. Specify all containers you need and pytest-docker will use Docker Compose to spin them up for the duration of your test suite.
Usage
Here is the basic recipe for writing a test that depends on a service that responds over HTTP:
import pytest import requests from requests.exceptions import ( ConnectionError, ) def is_responsive(url): """Check if something responds to ``url``.""" try: response = requests.get(url) if response.status_code == 200: return True except ConnectionError: return False @pytest.fixture(scope='session') def some_http_service(docker_ip, docker_services): """Ensure that "some service" is up and responsive.""" url = 'http://' % ( docker_ip, docker_services.port_for('abc', 123), ) docker_services.wait_until_responsive( timeout=30.0, pause=0.1, check=lambda: is_responsive(url) ) return url def test_something(some_service): """Sample test.""" response = requests.get(some_service) response.raise_for_status()
By default this plugin will try to open docker-compose.yml in your tests directory. If you need to use a custom location, override the docker_compose_file fixture inside your conftest.py file:
import pytest @pytest.fixture(scope='session') def docker_compose_file(pytestconfig): return os.path.join( str(pytestconfig.rootdir), 'mycustomdir' 'docker-compose.yml' )
You can allow this plugin to run your tests when Docker is not available. It will use the container port and localhost instead:
@pytest.fixture(scope='session') def docker_allow_fallback(): return True
Changelog
Version 0.4.0
Added -v option to docker-compose down to automatically remove all ephemeral volumes after tests run. This prevents disk space usage buildup on build machines that repeat this cycle very often with containers that write to disk (e.g. databases).
Version 0.3.0
Added --build option to docker-compose up command to automatically rebuild local containers.
Contributing
This py.test plug-in and its source code are made available to your under and MIT license. It is safe to use in commercial and closed-source applications. Read the license for details!
Found a bug? Think a new feature would make this plug-in more practical? No one is paid to support this software, but we welcome pull requests!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pytest-docker-0.4.0.tar.gz
.
File metadata
- Download URL: pytest-docker-0.4.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60ec503919c590bacf99d7c7b56b53d82cee2206b02804f8fd6e86d7b94f7413 |
|
MD5 | 3709998d3be130722743492b624d59d0 |
|
BLAKE2b-256 | e8f7fb4768fd66b83c46083aa1bb1d0b9c79b21e611134ae5eb5394110ace4ee |
File details
Details for the file pytest_docker-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_docker-0.4.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c5e4348cd246bdfda3bcc4b5221918405c28bbd69904a917a1f02a51f09d41 |
|
MD5 | 28f3cbfb14bc8046ed9c7da865fe1091 |
|
BLAKE2b-256 | e8f94b5603217985f6bbdbb877deb0b7480c7ce1b0ffa710051a838015e90b36 |
File details
Details for the file pytest_docker-0.4.0-py2-none-any.whl
.
File metadata
- Download URL: pytest_docker-0.4.0-py2-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18238162db8fba11100041fa5b46e426e22c15ddff0f49ecc5e5ab6b28fef17 |
|
MD5 | 3f57eec5b0658cf91c895fc62d01be68 |
|
BLAKE2b-256 | 284f2962a635669bb1f2f7cd6153bcfcdd1679455b815594b96da96f5789a788 |