{ "info": { "author": "zgallerie", "author_email": "developers@directbuy.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3" ], "description": "====================\nLovely Pytest Docker\n====================\n\n.. image:: https://img.shields.io/pypi/v/lovely-pytest-docker.svg\n :target: https://pypi.org/project/lovely-pytest-docker/\n\n.. image:: https://img.shields.io/pypi/pyversions/lovely-pytest-docker.svg\n :target: https://pypi.org/project/lovely-pytest-docker/\n\n.. image:: https://travis-ci.com/lovelysystems/lovely-pytest-docker.svg?branch=master\n :target: https://travis-ci.com/lovelysystems/lovely-pytest-docker\n\n\nCreate simple Pytest_ fixtures for writing integration tests based on Docker\ncontainers. The framework provides a service class to start and stop containers\nbased Docker Compose. Each single container can be started individually.\n\nSome parts of this package are taken from\nhttps://github.com/AndreLouisCaron/pytest-docker\n\n\nUsage with Pytest\n=================\n\nThe docker compose file should contain all desired containers and the ports\nshould be exposed. In the following example we want to start the app to test\nand a SQL database (Crate). Let's assume there is a ``Dockerfile`` for the app\nin the same folder as the docker compose file::\n\n version: \"3\"\n services:\n app:\n build: .\n ports:\n - \"8080\"\n depends_on:\n - \"crate\"\n\n crate:\n image: crate:latest\n ports:\n - \"4200\"\n\nIn the ``conftest.py`` file we can declare the docker fixtures for each service\nwe want to be able to start in the tests::\n\n import pytest\n\n @pytest.fixture(scope='session')\n def docker_app(docker_services):\n docker_services.start('app')\n public_port = docker_services.wait_for_service(\"app\", 8080)\n url = \"http://{docker_services.docker_ip}:{public_port}\".format(**locals())\n return url\n\n @pytest.fixture(scope='session')\n def docker_crate(docker_services):\n docker_services.start('crate')\n public_port = docker_services.wait_for_service(\"crate\", 4200)\n dsn = \"{docker_services.docker_ip}:{public_port}\".format(**locals())\n return dsn\n\nBy default the fixture will look for the ``docker-compose.yml`` file in the\n``tests`` subfolder of the path where ``pytest.ini`` resides (or the project's\nroot directory if no ini file is given - as in the tests example). In many\ncases you will want to override the location for the docker compose files. Just\noverwrite the ``docker_compose_files`` fixture in your ``conftest.py`` file::\n\n @pytest.fixture(scope='session')\n def docker_compose_files(pytestconfig):\n \"\"\"Get the docker-compose.yml absolute path.\n Override this fixture in your tests if you need a custom location.\n \"\"\"\n return [\n project_path('docker', 'docker-compose.yml'),\n ]\n\nIn your test file declare the fixtures you want to use::\n\n def test_something(docker_app, docker_crate):\n # e.g. initialize database\n ...\n # test something (e.g. request to docker_app)\n ...\n\nA working configuration and test example can be found in the ``tests`` folder\nof this package.\n\n\nExecution in Docker Container\n=============================\n\nIt's possible to execute a command inside one of the Docker containers. Use\nthe ``exec`` method of the ``docker_services`` fixture::\n\n def test_exec(docker_services):\n # the first argument is the service name of the compose file,\n # the following arguments build the command to run\n res = docker_services.exec('crate', 'ls', '-a')\n\n\nWait for Service\n================\n\nThe ``wait_for_service`` method of the service module checks whether the\ndocker service is really started. By default it makes a HTTP GET request to the\nserver's ``/`` endpoint. The service will retry to check until a timeout of\n30 seconds has passed.\n\nCustom Service Checker\n----------------------\n\nSome services may work differently and require a custom checker.\n\nCreate a custom service checker function which receives the IP address and the\nport as parameters::\n\n def custom_service_checker(ip_address, port):\n # if service is ready\n return True\n # otherwise return False\n\nIn the fixture provide the custom service checker function as ``check_service``\nparameter to the ``wait_for_service`` method::\n\n @pytest.fixture(scope='session')\n def docker_custom_service(docker_services):\n docker_services.start('custom_service')\n public_port = docker_services.wait_for_service(\n \"app\",\n 8080,\n check_service=custom_service_checker\n )\n url = \"http://{docker_services.docker_ip}:{public_port}\".format(**locals())\n return url\n\n\nRun Tests\n=========\n\nTests are held in the ``tests`` directory. Running tests is done via the\npytest package with::\n\n ./gradlew pytest\n\n\n.. _Pytest: http://doc.pytest.org\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/angry-penguins/lovely-pytest-docker", "keywords": "pytest testing docker compose", "license": "", "maintainer": "", "maintainer_email": "", "name": "penguins-pytest-docker", "package_url": "https://pypi.org/project/penguins-pytest-docker/", "platform": "", "project_url": "https://pypi.org/project/penguins-pytest-docker/", "project_urls": { "Homepage": "https://github.com/angry-penguins/lovely-pytest-docker" }, "release_url": "https://pypi.org/project/penguins-pytest-docker/0.0.7/", "requires_dist": [ "pytest" ], "requires_python": "", "summary": "Pytest testing utilities with docker containers.", "version": "0.0.7" }, "last_serial": 5667581, "releases": { "0.0.6": [ { "comment_text": "", "digests": { "md5": "004ae7ca579a306512b357f5c265a5e3", "sha256": "695c677b7ada26766497049b140a27efe340a4258a4bff5a702154e1861fcf6e" }, "downloads": -1, "filename": "penguins-pytest-docker-0.0.6.tar.gz", "has_sig": false, "md5_digest": "004ae7ca579a306512b357f5c265a5e3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6073, "upload_time": "2019-08-01T14:28:43", "url": "https://files.pythonhosted.org/packages/a5/8f/ecfb3d8cab1735dc314420e28f8a074b8f0549e6356dab2c1f2b553aa1ae/penguins-pytest-docker-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "f6718c1d085dde57fe15baab495a684c", "sha256": "205982032b1d8b7b954552f5cddb25bb3dd0e0f88f79ff1439f1c484efb56180" }, "downloads": -1, "filename": "penguins_pytest_docker-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "f6718c1d085dde57fe15baab495a684c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11241, "upload_time": "2019-08-12T16:58:22", "url": "https://files.pythonhosted.org/packages/86/29/405811544f2b8239c822f8018357ca3a11923f7aa63cb640631e52d08b66/penguins_pytest_docker-0.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4e07affcef015cb40f7804abfa458312", "sha256": "247baf72e07e76429b8ddacb0285eadf273bef181275f3972d431bfee525d0c3" }, "downloads": -1, "filename": "penguins-pytest-docker-0.0.7.tar.gz", "has_sig": false, "md5_digest": "4e07affcef015cb40f7804abfa458312", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6088, "upload_time": "2019-08-12T16:58:23", "url": "https://files.pythonhosted.org/packages/41/32/355c7a590f2be38d2873c1445882d9143a65fd353dc97479cbf3ab7e2682/penguins-pytest-docker-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f6718c1d085dde57fe15baab495a684c", "sha256": "205982032b1d8b7b954552f5cddb25bb3dd0e0f88f79ff1439f1c484efb56180" }, "downloads": -1, "filename": "penguins_pytest_docker-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "f6718c1d085dde57fe15baab495a684c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11241, "upload_time": "2019-08-12T16:58:22", "url": "https://files.pythonhosted.org/packages/86/29/405811544f2b8239c822f8018357ca3a11923f7aa63cb640631e52d08b66/penguins_pytest_docker-0.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4e07affcef015cb40f7804abfa458312", "sha256": "247baf72e07e76429b8ddacb0285eadf273bef181275f3972d431bfee525d0c3" }, "downloads": -1, "filename": "penguins-pytest-docker-0.0.7.tar.gz", "has_sig": false, "md5_digest": "4e07affcef015cb40f7804abfa458312", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6088, "upload_time": "2019-08-12T16:58:23", "url": "https://files.pythonhosted.org/packages/41/32/355c7a590f2be38d2873c1445882d9143a65fd353dc97479cbf3ab7e2682/penguins-pytest-docker-0.0.7.tar.gz" } ] }