[![image](https://img.shields.io/pypi/v/pytest-docker-service/0.2.8.svg)](https://pypi.python.org/pypi/pytest-docker-service)
[![image](https://img.shields.io/pypi/pyversions/pytest-docker-service/0.2.8.svg)](https://pypi.python.org/pypi/pytest-docker-service)
[![CI](https://github.com/ClementDelgrange/pytest-docker-service/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/ClementDelgrange/pytest-docker-service/actions/workflows/ci.yaml)
# 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/).
```python
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.
```python
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"]
...
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ClementDelgrange/pytest-docker-service",
"name": "pytest-docker-service",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9.0,<4.0",
"maintainer_email": "",
"keywords": "pytest,docker,devops,CI",
"author": "Cl\u00e9ment Delgrange",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/bb/0e/d44571ee50d4b3ac8b95504c294c315f76c7239e3353e0d5c19bf4166af1/pytest_docker_service-0.2.8.tar.gz",
"platform": null,
"description": "[![image](https://img.shields.io/pypi/v/pytest-docker-service/0.2.8.svg)](https://pypi.python.org/pypi/pytest-docker-service)\n[![image](https://img.shields.io/pypi/pyversions/pytest-docker-service/0.2.8.svg)](https://pypi.python.org/pypi/pytest-docker-service)\n[![CI](https://github.com/ClementDelgrange/pytest-docker-service/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/ClementDelgrange/pytest-docker-service/actions/workflows/ci.yaml)\n\n# pytest-docker-service\n\n`pytest-docker-service` is a pytest plugin for writing integration tests based on docker containers.\n\nThe plugin provides a *fixtures factory*: a configurable function to register fixtures.\n\nThe package has been developed and tested with Python 3.11, and pytest version 7.4.\n\n## Installation\nInstall `pytest-docker-service` with `pip`.\n\n```\npython -m pip install pytest-docker-service\n```\n\n## Usage\nYou just have to create a fixture in your `conftest.py` or in individual test modules, using the `docker_container` helper.\nFixture is created with the scope provided through the `scope` parameter.\nOther parameters are wrappers around the `docker-py` API (https://docker-py.readthedocs.io/en/stable/).\n\n```python\nimport requests\nfrom pytest_docker_service import docker_container\n\ncontainer = docker_container(\n scope=\"session\",\n image_name=\"kennethreitz/httpbin\",\n ports={\"80/tcp\": None},\n)\n\n\ndef test_status_code(container):\n port = container.port_map[\"80/tcp\"]\n\n status = 200\n response = requests.get(f\"http://127.0.0.1:{port}/status/{status}\")\n\n assert response.status_code == status\n```\n\nOf course, if you want to build your own docker image, it is possible.\nJust set the `build_path` parameter pointing to the directory containing the Dockerfile.\n```python\ncontainer = docker_container(\n scope=\"session\",\n image_name=\"my-image\",\n build_path=\"path/to/dockerfile/directory\",\n ports={\"80/tcp\": None},\n)\n\n\ndef test_status_code(container):\n port = container.port_map.[\"5432/tcp\"]\n\n ...\n\n```\n\n",
"bugtrack_url": null,
"license": "GNU GPL v3",
"summary": "pytest plugin to start docker container",
"version": "0.2.8",
"project_urls": {
"Homepage": "https://github.com/ClementDelgrange/pytest-docker-service",
"Repository": "https://github.com/ClementDelgrange/pytest-docker-service"
},
"split_keywords": [
"pytest",
"docker",
"devops",
"ci"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "89d470f6d4a2ec7483b9626018566a69543b3ca79f336072f1d90d09b133bb65",
"md5": "b5ff1bd807a46e93f32c70bf62cdec6a",
"sha256": "ffdd602c654d06c70be64c264930983724455b22013b90ecf2723ad90c7016e3"
},
"downloads": -1,
"filename": "pytest_docker_service-0.2.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b5ff1bd807a46e93f32c70bf62cdec6a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9.0,<4.0",
"size": 17116,
"upload_time": "2024-01-03T21:47:19",
"upload_time_iso_8601": "2024-01-03T21:47:19.057548Z",
"url": "https://files.pythonhosted.org/packages/89/d4/70f6d4a2ec7483b9626018566a69543b3ca79f336072f1d90d09b133bb65/pytest_docker_service-0.2.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bb0ed44571ee50d4b3ac8b95504c294c315f76c7239e3353e0d5c19bf4166af1",
"md5": "a5b6500126d2087ea5950ae3252f1fa1",
"sha256": "46b5a8be72b88539b4b84b5e26e36f96da017d58d2af2375e887c5246155a025"
},
"downloads": -1,
"filename": "pytest_docker_service-0.2.8.tar.gz",
"has_sig": false,
"md5_digest": "a5b6500126d2087ea5950ae3252f1fa1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9.0,<4.0",
"size": 16139,
"upload_time": "2024-01-03T21:47:20",
"upload_time_iso_8601": "2024-01-03T21:47:20.647825Z",
"url": "https://files.pythonhosted.org/packages/bb/0e/d44571ee50d4b3ac8b95504c294c315f76c7239e3353e0d5c19bf4166af1/pytest_docker_service-0.2.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-03 21:47:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ClementDelgrange",
"github_project": "pytest-docker-service",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pytest-docker-service"
}