{ "info": { "author": "Roald Storm", "author_email": "roaldstorm@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Pytest", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Testing" ], "description": "pytest-docker-compose\n=====================\n.. image:: https://circleci.com/gh/pytest-docker-compose/pytest-docker-compose/tree/master.svg?style=svg\n :target: https://circleci.com/gh/pytest-docker-compose/pytest-docker-compose/tree/master\n\nThis package contains a `pytest`_ plugin for integrating Docker Compose into your automated integration tests.\n\nGiven a path to a ``docker-compose.yml`` file, it will automatically build the project at the start of the test run, bring the containers up before each test starts, and tear them down after each test ends.\n\n\nDependencies\n------------\nMake sure you have `Docker`_ installed.\n\nThis plugin is automatically tested against the following software:\n\n- Python 3.5 and 3.6.\n- pytest 3, 4 and 5.\n\n.. note:: This plugin is **not** compatible with Python 2.\n\nLocally I tested it successfully against Python 3.7 as well but 3.7 proved hard to integrate into circleCI so it's not officially supported.\n\nInstallation\n------------\nInstall the plugin using pip::\n\n > pip install pytest-docker-compose\n\n\nUsage\n-----\nFor performance reasons, the plugin is not enabled by default, so you must activate it manually in the tests that use it:\n\n.. code-block:: python\n\n pytest_plugins = [\"docker_compose\"]\n\nSee `Installing and Using Plugins`_ for more information.\n\nTo interact with Docker containers in your tests, use the following fixtures, these fixtures tell docker-compose to start all the services and then they can fetch the associated containers for use in a test:\n\n``function_scoped_container_getter``\n An object that fetches containers of the Docker ``compose.container.Container`` objects running during the test. The containers are fetched using ``function_scoped_container_getter.get('service_name')`` These containers each have an extra attribute called ``network_info`` added to them. This attribute has a list of ``pytest_docker_compose.NetworkInfo`` objects.\n\n This information can be used to configure API clients and other objects that will connect to services exposed by the Docker containers in your tests.\n\n ``NetworkInfo`` is a container with the following fields:\n\n - ``container_port``: The port (and usually also protocol name) exposed\n internally to the container. You can use this value to find the correct\n port for your test, when the container exposes multiple ports.\n\n - ``hostname``: The hostname (usually \"localhost\") to use when connecting to\n the service from the host.\n\n - ``host_port``: The port number to use when connecting to the service from\n the host.\n\n``docker_project``\n The ``compose.project.Project`` object that the containers are built from.\n This fixture is generally only used internally by the plugin.\n\nTo use the following fixtures please read `Use wider scoped fixtures`_.\n\n``class_scoped_container_getter``\n Similar to ``function_scoped_container_getter`` just with a wider scope.\n\n``module_scoped_container_getter``\n Similar to ``function_scoped_container_getter`` just with a wider scope.\n\n``session_scoped_container_getter``\n Similar to ``function_scoped_container_getter`` just with a wider scope.\n\nWaiting for Services to Come Online\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nThe fixtures called ``'scope'_scoped_container_getter`` will wait until every container is up before handing control over to the test.\n\nHowever, just because a container is up does not mean that the services running on it are ready to accept incoming requests yet!\n\nIf your tests need to wait for a particular condition (for example, to wait for an HTTP health check endpoint to send back a 200 response), make sure that your fixtures account for this.\n\nHere's an example of a fixture called ``wait_for_api`` that waits for an HTTP service to come online before a test called ``test_read_and_write`` can run.\n\n.. code-block:: python\n\n import pytest\n import requests\n from urllib.parse import urljoin\n from urllib3.util.retry import Retry\n from requests.adapters import HTTPAdapter\n\n pytest_plugins = [\"docker_compose\"]\n\n # Invoking this fixture: 'function_scoped_container_getter' starts all services\n @pytest.fixture(scope=\"function\")\n def wait_for_api(function_scoped_container_getter):\n \"\"\"Wait for the api from my_api_service to become responsive\"\"\"\n request_session = requests.Session()\n retries = Retry(total=5,\n backoff_factor=0.1,\n status_forcelist=[500, 502, 503, 504])\n request_session.mount('http://', HTTPAdapter(max_retries=retries))\n\n service = function_scoped_container_getter.get(\"my_api_service\").network_info[0]\n api_url = \"http://%s:%s/\" % (service.hostname, service.host_port)\n assert request_session.get(api_url)\n return request_session, api_url\n\n\n def test_read_and_write(wait_for_api):\n \"\"\"The Api is now verified good to go and tests can interact with it\"\"\"\n request_session, api_url = wait_for_api\n data_string = 'some_data'\n request_session.put('%sitems/2?data_string=%s' % (api_url, data_string))\n item = request_session.get(urljoin(api_url, 'items/2')).json()\n assert item['data'] == data_string\n request_session.delete(urljoin(api_url, 'items/2'))\n\nUse wider scoped fixtures\n~~~~~~~~~~~~~~~~~~~~~~~~~\nThe ``function_scoped_container_getter`` fixture uses \"function\" scope, meaning that all of the containers are torn down after each individual test.\n\nThis is done so that every test gets to run in a \"clean\" environment. However, this can potentially make a test suite take a very long time to complete.\n\nThere are two options to make containers persist beyond a single test. The best way is to use the fixtures that are explicitly scoped to different scopes. There are three additional fixtures for this purpose: ``class_scoped_container_getter``, ``module_scoped_container_getter`` and ``session_scoped_container_getter``. Notice that you need to be careful when using these! There are two main caveats to keep in mind:\n\n1. Manage your scope correctly, using 'module' scope and 'function' scope in one single file will throw an error! This is because the module scoped fixture will spin up the containers and then the function scoped fixture will try to spin up the containers again. Docker compose does not allow you to spin up containers twice.\n2. Clean up your environment after each test. Because the containers are not restarted their environments can carry the information from previous tests. Therefore you need to be very carefull when designing your tests such that they leave the containers in the same state that it started in or you might run into difficult to understand behaviour.\n\nA second method to make containers persist beyond a single test is to supply the --use-running-containers flag to pytest like so:\n\n.. code-block:: bash\n\n pytest --use-running-containers\n\nWith this flag, pytest-docker-compose checks that all containers are running\nduring the project creation. If they are not running a warning is given and\nthey are spun up anyways. They are then used for all the tests and NOT TORE\nDOWN afterwards.\n\nThis mode is best used in combination with the '--docker-compose-no-build' flag since the newly build containers won't be used anyways. like so:\n\n.. code-block:: bash\n\n pytest --docker-compose-no-build --use-running-containers\n\nIt is off course possible to add these options to ``pytest.ini``.\n\nNotice that for this mode the scoping of the fixtures becomes less important since the containers are fully persistent throughout all tests. I only recommend using this if your network takes excessively long to spin up/tear down. It should really be a last resort and you should probably look into speeding up your network instead of using this.\n\n\n\nRunning Integration Tests\n-------------------------\nUse `pytest`_ to run your tests as normal:\n\n.. code-block:: sh\n\n pytest\n\nBy default, this will look for a ``docker-compose.yml`` file in the current\nworking directory. You can specify a different file via the\n``--docker-compose`` option:\n\n.. code-block:: sh\n\n pytest --docker-compose=/path/to/docker-compose.yml\n\n.. tip::\n Alternatively, you can specify this option in your ``pytest.ini`` file:\n\n .. code-block:: ini\n\n [pytest]\n addopts = --docker-compose=/path/to/docker-compose.yml\n\n The option will be ignored for tests that do not use this plugin.\n\n See `Configuration Options`_ for more information on using configuration\n files to modify pytest behavior.\n\nRemove volumes after tests\n--------------------------\nThere is another configuration option that will delete the volumes of containers after running.\n\n.. code-block:: sh\n\n pytest --docker-compose-remove-volumes\n\nThis option will be ignored if the plugin is not used. Again, this option can also be added to the pytest.ini file.\n\nFor more examples on how to use this plugin look at the testing suite of this plugin itself! It will give you some examples for configuring pytest.ini and how to use the different fixtures to run docker containers.\n\n.. _Configuration Options: https://docs.pytest.org/en/latest/customize.html#adding-default-options\n.. _Docker: https://www.docker.com/\n.. _Installing and Using Plugins: https://docs.pytest.org/en/latest/plugins.html#requiring-loading-plugins-in-a-test-module-or-conftest-file\n.. _pytest: https://docs.pytest.org/\n.. _pytest-xdist: https://github.com/pytest-dev/pytest-xdist\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pytest-docker-compose/pytest-docker-compose", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pytest-docker-compose", "package_url": "https://pypi.org/project/pytest-docker-compose/", "platform": "", "project_url": "https://pypi.org/project/pytest-docker-compose/", "project_urls": { "Homepage": "https://github.com/pytest-docker-compose/pytest-docker-compose" }, "release_url": "https://pypi.org/project/pytest-docker-compose/3.1.2/", "requires_dist": [ "docker-compose", "pytest (>=3.3)" ], "requires_python": "", "summary": "Manages Docker containers during your integration tests", "version": "3.1.2" }, "last_serial": 5910676, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "be61954f1ca14747d8979710f812ed25", "sha256": "54c7a6c7e3df04e0bf4c344607a7363bb459d2bafd6eab85ddcd9bb4c1125cfd" }, "downloads": -1, "filename": "pytest_docker_compose-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "be61954f1ca14747d8979710f812ed25", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4351, "upload_time": "2018-03-26T00:51:05", "url": "https://files.pythonhosted.org/packages/91/9b/47e51e1f1078ece2e689c54fac0c7f0e79c54a97263caca6dbef06cda9b0/pytest_docker_compose-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "48cbd7fbd864ea1e24903cd2e011f2ff", "sha256": "06c031fa2db83a9d16fab15eb91d740ebf657359dd1d58885341895db4174315" }, "downloads": -1, "filename": "pytest-docker-compose-1.0.0.tar.gz", "has_sig": false, "md5_digest": "48cbd7fbd864ea1e24903cd2e011f2ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8527, "upload_time": "2018-03-26T00:51:06", "url": "https://files.pythonhosted.org/packages/09/4a/05d8d08d9754416c20b743d499c2c7429e8fe3c656be970e620fc7dd5b9a/pytest-docker-compose-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "0bcb0554df4f83037323c853da6cc6e0", "sha256": "3589b15c209628e9d408671acecf10444d32fa3cc65295c8212ff10bc187a2f9" }, "downloads": -1, "filename": "pytest_docker_compose-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "0bcb0554df4f83037323c853da6cc6e0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8636, "upload_time": "2018-03-26T01:00:13", "url": "https://files.pythonhosted.org/packages/78/58/ea49b322ddb188ce62febdc7c44e4e84bc76e522103d47ed6d2742bbbcf9/pytest_docker_compose-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "686ad008e466eb6f2b42cfccf46b83e2", "sha256": "ca82c60c9fb59e098a6be306f7b1d36fb2a494cbc2e4baf2d9b6aa5844a9bc58" }, "downloads": -1, "filename": "pytest-docker-compose-1.0.1.tar.gz", "has_sig": false, "md5_digest": "686ad008e466eb6f2b42cfccf46b83e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9201, "upload_time": "2018-03-26T01:00:14", "url": "https://files.pythonhosted.org/packages/aa/e1/430252ff01f55497d6e480269837e411bfebaffaea9fee244abcc1838e43/pytest-docker-compose-1.0.1.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "72c49872f8c142af5553c9337fcd661b", "sha256": "87ec70b904fddd0d2bb1e5164187c1d1235a93990a41435ab2a1a23390245081" }, "downloads": -1, "filename": "pytest_docker_compose-2.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "72c49872f8c142af5553c9337fcd661b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11481, "upload_time": "2019-07-11T07:23:30", "url": "https://files.pythonhosted.org/packages/04/43/5f8a7490d78ebf4cde09dcd8b267ba742c4953303078c4239740889b287c/pytest_docker_compose-2.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8aec5bb7b78fb4f75b75cb34ae7b197a", "sha256": "0e8aa9e7ed09b726a885910f1ec861b76d96f592294242b72d0dfc14d861fae1" }, "downloads": -1, "filename": "pytest-docker-compose-2.0.0.tar.gz", "has_sig": false, "md5_digest": "8aec5bb7b78fb4f75b75cb34ae7b197a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10990, "upload_time": "2019-07-11T07:23:31", "url": "https://files.pythonhosted.org/packages/29/e9/7cd005f23965c4f836339b3f340e1742c441cd20c8a13d86fa44e040d3b7/pytest-docker-compose-2.0.0.tar.gz" } ], "3.0.0": [ { "comment_text": "", "digests": { "md5": "9ceadb4465e3611b71c4e89f3f493e63", "sha256": "a19bd51826d6d193cd92a09c53e7476ef24b645d8fbaf7cb61005226cc81039c" }, "downloads": -1, "filename": "pytest_docker_compose-3.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "9ceadb4465e3611b71c4e89f3f493e63", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11787, "upload_time": "2019-08-14T07:50:35", "url": "https://files.pythonhosted.org/packages/f2/c7/41a895d0bac11c12a84d555505554504d61f1556076ffd550d5d473e3069/pytest_docker_compose-3.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fafb15ca2e25c68b50f1627b0fd5124d", "sha256": "93ce3e1c948fca8c1d093caa523ab380bfa0f22da2d1af490e4ca27c9abd4822" }, "downloads": -1, "filename": "pytest-docker-compose-3.0.0.tar.gz", "has_sig": false, "md5_digest": "fafb15ca2e25c68b50f1627b0fd5124d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12474, "upload_time": "2019-08-14T07:50:36", "url": "https://files.pythonhosted.org/packages/84/7a/4d77b02bbd8f8724aa8840acbc6a1d4e705007e1613c6046c9061a75a364/pytest-docker-compose-3.0.0.tar.gz" } ], "3.1.0": [ { "comment_text": "", "digests": { "md5": "1d1af971c65f6602c45721e3fda2f51b", "sha256": "d4819b105617b5dff9db5b154a3ee7ce6926e7905d38e03314f4b5d1c4e91de4" }, "downloads": -1, "filename": "pytest_docker_compose-3.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1d1af971c65f6602c45721e3fda2f51b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11801, "upload_time": "2019-08-26T07:58:14", "url": "https://files.pythonhosted.org/packages/70/21/1a3beaaad9275e165805ff0b65ff8fdd957bccb8ab2cc67c68c4535b0c57/pytest_docker_compose-3.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d43f6ae0c92b8dad31f29033ffafd10e", "sha256": "38afc4b849de2e9d80f5cf22408d6fe0fd477a8bc81a883b969c949946388860" }, "downloads": -1, "filename": "pytest-docker-compose-3.1.0.tar.gz", "has_sig": false, "md5_digest": "d43f6ae0c92b8dad31f29033ffafd10e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12475, "upload_time": "2019-08-26T07:58:16", "url": "https://files.pythonhosted.org/packages/7e/4f/0fb304f8494ee0e7e079e7422b6dd29b396ce47bfd07730f57d92230a10c/pytest-docker-compose-3.1.0.tar.gz" } ], "3.1.1": [ { "comment_text": "", "digests": { "md5": "73f66392f053d60bbee86d435d6a8f88", "sha256": "d74b88777998b82a2498dc2babd1a9bfca007b259ea65723e0fa594ea9c12fca" }, "downloads": -1, "filename": "pytest_docker_compose-3.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "73f66392f053d60bbee86d435d6a8f88", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11982, "upload_time": "2019-09-02T10:23:54", "url": "https://files.pythonhosted.org/packages/a1/a5/827dc76d4022f8dbc6bfe7ead4eb44f5de6f2c2c9fd31ef1e0bc08ab20b6/pytest_docker_compose-3.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8556cb6ecb434f7d435d5ce929701849", "sha256": "14434d2060bd81f358684a1c0261979cb5a53e8eadf50e73d6547fad3b72b2d0" }, "downloads": -1, "filename": "pytest-docker-compose-3.1.1.tar.gz", "has_sig": false, "md5_digest": "8556cb6ecb434f7d435d5ce929701849", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13416, "upload_time": "2019-09-02T10:23:55", "url": "https://files.pythonhosted.org/packages/85/94/64d41b51f3dc58ba55ebd95a3aa138acd54d4041baf727cc2da2b4ae88a0/pytest-docker-compose-3.1.1.tar.gz" } ], "3.1.2": [ { "comment_text": "", "digests": { "md5": "60d5cb788e0080c8f87b107d7b4476d6", "sha256": "59462d39df9b5e09f4ddeb46f0d062b77a94dbb8d475e1a48cdea3e46aa6cee5" }, "downloads": -1, "filename": "pytest_docker_compose-3.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "60d5cb788e0080c8f87b107d7b4476d6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12065, "upload_time": "2019-10-01T06:44:35", "url": "https://files.pythonhosted.org/packages/88/71/26d4ffc5ca6538b74ac1825b5c4fc1e6c92edaa2932be31555a9fc75fe6d/pytest_docker_compose-3.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cf186ab1976e110a156ebf5b53f0c441", "sha256": "f0d5c7b7e31458862aca3e5668aa6d32c5e22a177ef77c1898c74d95c6590a79" }, "downloads": -1, "filename": "pytest-docker-compose-3.1.2.tar.gz", "has_sig": false, "md5_digest": "cf186ab1976e110a156ebf5b53f0c441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13501, "upload_time": "2019-10-01T06:44:37", "url": "https://files.pythonhosted.org/packages/26/d8/72ed036db86f0df89bb5a7a3b2db00d53f1ff4815b28435ac80875cdb182/pytest-docker-compose-3.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "60d5cb788e0080c8f87b107d7b4476d6", "sha256": "59462d39df9b5e09f4ddeb46f0d062b77a94dbb8d475e1a48cdea3e46aa6cee5" }, "downloads": -1, "filename": "pytest_docker_compose-3.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "60d5cb788e0080c8f87b107d7b4476d6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12065, "upload_time": "2019-10-01T06:44:35", "url": "https://files.pythonhosted.org/packages/88/71/26d4ffc5ca6538b74ac1825b5c4fc1e6c92edaa2932be31555a9fc75fe6d/pytest_docker_compose-3.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cf186ab1976e110a156ebf5b53f0c441", "sha256": "f0d5c7b7e31458862aca3e5668aa6d32c5e22a177ef77c1898c74d95c6590a79" }, "downloads": -1, "filename": "pytest-docker-compose-3.1.2.tar.gz", "has_sig": false, "md5_digest": "cf186ab1976e110a156ebf5b53f0c441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13501, "upload_time": "2019-10-01T06:44:37", "url": "https://files.pythonhosted.org/packages/26/d8/72ed036db86f0df89bb5a7a3b2db00d53f1ff4815b28435ac80875cdb182/pytest-docker-compose-3.1.2.tar.gz" } ] }