{ "info": { "author": "Martin Bukatovi\u010d", "author_email": "mbukatov@redhat.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Pytest", "Intended Audience :: Developers", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Testing" ], "description": "pytest-ansible-playbook-runner\n===================================\n\nThis repository contains `pytest`_ `plugin`_ which provides an easy way\nto run particular `ansible playbooks`_ during setup phase of a test case.\nThis is useful when\nyou already have some playbook files you would like to reuse during test setup\nor plan to maintain test setup in ansible playbooks for you to be able to\nuse it both during test run setup and directly via ansible for other purposes\n(automatically during deployment or manually when needed).\n\nCompared with `pytest-ansible`_ module, this module doesn't allow you to\ninspect `ansible facts`_ or details about results of each ansible task, nor\ndoest it allow to specify and execute an ansible task directly. So if you need\nany of that, go for `pytest-ansible`_ instead. This plugin provides the only\nmissing ansible feature which `pytest-ansible`_ is not supposed to provide - to\nrun ansible playbook file directly.\n\nInitial structure of this repository was generated with `Cookiecutter`_\nalong with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template.\n\n\nFeatures\n--------\n\n#### Notes:\n\n- The plugin provides ``ansible_playbook`` `pytest fixture`_, which allows\n one to run one or more ansible playbooks during test setup or tear down of a\n test case.\n- It also provides `context manager`_ ``pytest_ansible_playbook.runner()``\n which can be used to build custom fixtures with any `scope`_ or to execute\n setup and/or teardown playbooks in a code of a test case.\n- It's compatible with python3 (playbooks are executed via\n running ``ansible-playbook`` in subprocess instead of using api\n of ansible python module).\n- Doesn't allow you to configure ansible in any way, all changes of ansible\n setup needs to be done in ansible playbooks, variable or config files.\n This encourages you to maintain a clear separation of ansible playbooks\n and the tests.\n\n\n\n### Key features:\n\n1. An option to run arbitrary playbooks in the middle of the test\n```python\ndef test_something(ansible_playbook,....):\n ...\n ansible_playbook.run_playbook('my_playbook.yml')\n ...\n```\n2. An option to add teardown playbooks in the middle of the test:\n```python\ndef test_something(ansible_playbook,....):\n ...\n ansible_playbook.add_to_teardown({'file': 'my_playbook.yml', 'extra_vars': {})\n ...\n```\n3. Return values have been added to every playbook run. The return value respects playbook execution order and for every host:\n```python\ndef test_something(ansible_playbook,....):\n ...\n ret = ansible_playbook.run_playbook('my_playbook.yml')\n assert ret['localhost'][0]['msg'] == 'line added'\n```\n4. A test can pass arguments to the playbooks it runs. Thus the playbook has changed from string to dictionary:\n```python\ndef test_something(ansible_playbook,....):\n ...\n ansible_playbook.run_playbook('my_playbook.yml', {'play_host_groupd': 'some_ansible_group', 'param1': 'value1'})\n ...\n```\n5. Mark setup / teardown syntax:\n```python\n@pytest.mark.ansible_playbook_setup(\n {'file': 'some_playbook.yml', 'extra_vars': {'play_host_groupd': 'some_ansible_group', 'param1': 'value1'}}\n)\n@pytest.mark.ansible_playbook_teardown(\n {'file': 'my_teardown1.yml', 'extra_vars': {'play_host_groupd': 'some_ansible_group', 'param1': 'value1'}},\n {'file': 'my_teardown2.yml', 'extra_vars': {'play_host_groupd': 'some_ansible_group', 'param1': 'value1'}}\n)\ndef test_something(ansible_playbook,....):\n ...\n ansible_playbook.run_playbook('my_playbook.yml', {'play_host_groupd': 'some_ansible_group', 'param1': 'value1'})\n ...\n```\n\n\n\nNow the pytest plugin uses a separate module: playbook_runner.\nhttps://github.com/final-israel/playbook_runner\nThis is because other tools may want to also run playbooks not necessarily as a part of the pytest framework.\n\n\nRequirements\n------------\n\nAnsible should be installed (so that ``ansible-playbook`` binary is\navailable in PATH). Use version provided by packaging system of your operation\nsystem.\n\n\nInstallation\n------------\n\nYou can either install `stable release from PyPI`_ or use latest development\nversion from master branch.\n\n\nInstalling stable release\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can install \"pytest-ansible-playbook-runner\" via `pip`_ from `PyPI`_::\n\n $ pip install pytest-ansible-playbook-runner\n\n\nInstalling latest development version\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe suggested way to install from sources of current master branch is\nvia `python virtual enviroment`_::\n\n $ cd pytest-ansible-playbook-runner\n $ virtualenv .env\n $ source .env/bin/activate\n $ pip install -e .\n\nNote that you can use `virtualenvwrapper`_ to simplify this workflow.\n\n\nUsage\n-----\n\nWhen the plugin is installed, you can use the following command-line\nparameters::\n\n py.test \\\n [--ansible-playbook-directory ] \\\n [--ansible-playbook-inventory ]\n\nWhere ```` is a directory which contains\nansible playbooks and any other ansible files such as\nconfiguration or roles if needed. A ``ansible-playbook`` process will be able\nto access the files stored there, since this directory is set as cwd (current\nworking directory) of the ansible process.\n\nThe ```` is file with `ansible inventory`_. You can\nuse either an absolute path or a relative path within the ansible directory\nspecified via the 1st option.\n\nNote that the option names were chosen this way so that it doesn't conflict\nwith `pytest-ansible`_ plugin.\n\n\nUsing ansible playbook fixture\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe plugin provides a single pytest fixture called ``ansible_playbook``. To\nspecify playbooks to be executed by the fixture, use the following `pytest\nmarkers`_:\n\n* ``@pytest.mark.ansible_playbook_setup('playbook.yml')``\n* ``@pytest.mark.ansible_playbook_teardown('playbook.yml')``\n\nNote that you can list multiple playbooks in the marker if needed, eg.::\n\n @pytest.mark.ansible_playbook_setup('playbook.01.yml', 'playbook.02.yml')\n\nboth playbooks would be executed in the given order.\n\nHere is an example how to specify 2 playbooks to be run during setup phase\nof a test case and one for the teardown::\n\n @pytest.mark.ansible_playbook_setup('setup_foo.yml', 'bar.yml')\n @pytest.mark.ansible_playbook_teardown('teardown_foo.yml')\n def test_foo(ansible_playbook):\n \"\"\"\n Some testing is done here.\n \"\"\"\n\nWhile using markers without ``ansible_playbook`` fixture like this is valid::\n\n @pytest.mark.ansible_playbook_setup('setup_foo.yml')\n @pytest.mark.ansible_playbook_teardown('teardown_foo.yml')\n def test_foo():\n \"\"\"\n Some testing is done here.\n \"\"\"\n\nno playbook would be executed in such case.\n\nAlso note that using a marker without any playbook parameter or using the\nfixture without any marker is not valid and would cause an error.\n\n\nUsing ansible playbook runner function\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nFunction ``pytest_ansible_playbook.runner`` is a `context manager`_ which can\nbe used either to create a custom `pytest fixture`_ or to run playbooks within\na test case.\n\nCreating custom fixture this way is useful when you want to:\n\n* define set of setup/teardown playbooks and use it with multiple test cases,\n* run setup or teardown playbooks in any fixture `scope`_\n (to overcome the fact that ``ansible_playbook`` has ``fuction`` scope),\n* combine run of given setup/teardown playbooks with other non\n ansible setup or teardown steps\n (to overcome the fact that you can't use ``ansible_playbook`` fixture to run\n setup/teardown for another fixture, because `pytest doesn't expect fixtures\n to have markers`_).\n* specify that teardown playbooks are skipped when a test case fails\n\nExample of simple custom fixture::\n\n iport pytest\n from pytest_ansible_playbook import runner\n\n @pytest.fixture(scope=\"session\")\n def custom_fixture(request):\n setup_playbooks = ['setup_foo.yml', 'setup_bar.yml']\n teardown_playbooks = ['teardown_foo.yml', 'teardown_bar.yml']\n with runner(request, setup_playbooks, teardown_playbooks):\n # here comes code executed during setup, after running the setup\n # playbooks\n yield\n # here you can place code to be executed during teardown, but\n # before running the teardown playbooks\n\n def test_bar(custom_fixture):\n assert 1 == 1\n\nAnd here is an example of using the fixture inside a test case directly::\n\n from pytest_ansible_playbook import runner\n\n def test_foo(request):\n with runner(request, ['setup_foo.yml'], ['teardown_foo.yml']):\n # code here is executed after the setup playbooks, but before the\n # teardown ones\n assert 1 == 1\n\nIf you want to avoid running teardown playbook(s) when a test case fails, use\n``skip_teardown`` argument of the runner::\n\n with runner(\n request, teardown_playbooks=['teardown.yml'], skip_teardown=True):\n assert 1 == 0\n\n\nContributing\n------------\n\nContributions are very welcome. Tests can be run with `tox`_, please ensure\nthe coverage at least stays the same before you submit a pull request.\n\n\nLicense\n-------\n\nDistributed under the terms of the `Apache License 2.0`_ license,\n\"pytest-ansible-playbook-runner\" is free and open source software\n\n\nIssues\n------\n\nIf you encounter any problems, please `file an issue`_ along with a detailed\ndescription.\n\n.. _`file an issue`: https://github.com/final-israel/pytest-ansible-playbook-runner/issues\n.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter\n.. _`@hackebrot`: https://github.com/hackebrot\n.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin\n.. _`pytest`: http://docs.pytest.org/en/latest/\n.. _`pytest fixture`: http://doc.pytest.org/en/latest/fixture.html\n.. _`pytest markers`: http://doc.pytest.org/en/latest/example/markers.html\n.. _`plugin`: http://doc.pytest.org/en/latest/plugins.html\n.. _`tox`: https://tox.readthedocs.io/en/latest/\n.. _`pip`: https://pypi.python.org/pypi/pip/\n.. _`PyPI`: https://pypi.python.org/pypi\n.. _`stable release from PyPI`: https://pypi.org/project/pytest-ansible-playbook-runner/\n.. _`python virtual enviroment`: https://virtualenv.pypa.io/en/stable/\n.. _`virtualenvwrapper`: https://virtualenvwrapper.readthedocs.io/en/latest/\n.. _`pytest-ansible`: https://pypi.python.org/pypi/pytest-ansible\n.. _`ansible playbooks`: https://docs.ansible.com/ansible/playbooks.html\n.. _`ansible facts`: https://docs.ansible.com/ansible/playbooks_variables.html#information-discovered-from-systems-facts\n.. _`ansible inventory`: https://docs.ansible.com/ansible/intro_inventory.html\n.. _`Apache License 2.0`: http://www.apache.org/licenses/LICENSE-2.0\n.. _`context manager`: https://docs.python.org/3.6/library/stdtypes.html#context-manager-types\n.. _`scope`: https://docs.pytest.org/en/latest/fixture.html#scope-sharing-a-fixture-instance-across-tests-in-a-class-module-or-session\n.. _`pytest doesn't expect fixtures to have markers`: https://github.com/pytest-dev/pytest/issues/3664\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/final-israel/pytest-ansible-playbook-runner", "keywords": "", "license": "Apache 2.0", "maintainer": "Pavel Rogovoy", "maintainer_email": "pavelr@final.co.il", "name": "pytest-ansible-playbook-runner", "package_url": "https://pypi.org/project/pytest-ansible-playbook-runner/", "platform": "", "project_url": "https://pypi.org/project/pytest-ansible-playbook-runner/", "project_urls": { "Homepage": "https://github.com/final-israel/pytest-ansible-playbook-runner" }, "release_url": "https://pypi.org/project/pytest-ansible-playbook-runner/0.0.2/", "requires_dist": [ "pytest (>=3.1.0)", "playbook-runner" ], "requires_python": "", "summary": "Pytest fixture which runs given ansible playbook file.", "version": "0.0.2" }, "last_serial": 5212401, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d22a82c17d7814684a0eaf10c9b165eb", "sha256": "a8c3391a1acc7e9ea1e64360079fb9f43d857bcb38a0d2522e29106186ca3168" }, "downloads": -1, "filename": "pytest_ansible_playbook_runner-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d22a82c17d7814684a0eaf10c9b165eb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12367, "upload_time": "2019-05-01T09:28:38", "url": "https://files.pythonhosted.org/packages/4f/9e/a709fff45abd9a17699e8a7d16b586c7a736370f19cf600a6a3242ffbe0f/pytest_ansible_playbook_runner-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c5b7fc3e493b798f8d531162c32762a5", "sha256": "b23cd3c50ef9bb6c1d3c8f617e2e9e5c733ad2497c1a6b0d00a58e86cbb4ded4" }, "downloads": -1, "filename": "pytest-ansible-playbook-runner-0.0.1.tar.gz", "has_sig": false, "md5_digest": "c5b7fc3e493b798f8d531162c32762a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11702, "upload_time": "2019-05-01T09:28:41", "url": "https://files.pythonhosted.org/packages/16/86/6e4d4137c9b7b798d3ee4f7f499798dce141a4f9ac4d83091fe2ba445af1/pytest-ansible-playbook-runner-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "e62e866b4eaded086d01017519bbfb95", "sha256": "9d56af89fa84a145e8fa0267ccf11775c46dded4f965d7d7353ff7f8b2dac872" }, "downloads": -1, "filename": "pytest_ansible_playbook_runner-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "e62e866b4eaded086d01017519bbfb95", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12842, "upload_time": "2019-05-01T11:42:39", "url": "https://files.pythonhosted.org/packages/fb/aa/3622cb80719675849f4f56424336df403bff30dab9e6af14380fbe7d62d6/pytest_ansible_playbook_runner-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afc3ee2e7bd72213c378f381044138c3", "sha256": "57b3887e968a576a03e666ef8a0750e05e7fbd268416d3f1e0a9eee00e706b2e" }, "downloads": -1, "filename": "pytest-ansible-playbook-runner-0.0.2.tar.gz", "has_sig": false, "md5_digest": "afc3ee2e7bd72213c378f381044138c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12718, "upload_time": "2019-05-01T11:42:40", "url": "https://files.pythonhosted.org/packages/c8/b6/2f9f5ddf66fb399ab7be1f80036ec0e36f9d0cb68fd2c3a21c739a27337a/pytest-ansible-playbook-runner-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e62e866b4eaded086d01017519bbfb95", "sha256": "9d56af89fa84a145e8fa0267ccf11775c46dded4f965d7d7353ff7f8b2dac872" }, "downloads": -1, "filename": "pytest_ansible_playbook_runner-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "e62e866b4eaded086d01017519bbfb95", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12842, "upload_time": "2019-05-01T11:42:39", "url": "https://files.pythonhosted.org/packages/fb/aa/3622cb80719675849f4f56424336df403bff30dab9e6af14380fbe7d62d6/pytest_ansible_playbook_runner-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afc3ee2e7bd72213c378f381044138c3", "sha256": "57b3887e968a576a03e666ef8a0750e05e7fbd268416d3f1e0a9eee00e706b2e" }, "downloads": -1, "filename": "pytest-ansible-playbook-runner-0.0.2.tar.gz", "has_sig": false, "md5_digest": "afc3ee2e7bd72213c378f381044138c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12718, "upload_time": "2019-05-01T11:42:40", "url": "https://files.pythonhosted.org/packages/c8/b6/2f9f5ddf66fb399ab7be1f80036ec0e36f9d0cb68fd2c3a21c739a27337a/pytest-ansible-playbook-runner-0.0.2.tar.gz" } ] }