{"id":14965258,"url":"https://github.com/saltstack/pytest-shell-utilities","last_synced_at":"2025-04-09T23:17:34.333Z","repository":{"id":38818954,"uuid":"422087584","full_name":"saltstack/pytest-shell-utilities","owner":"saltstack","description":"Simple pytest(pytest.org) plugin which provides fixtures and code to help with running shell commands on tests","archived":false,"fork":false,"pushed_at":"2024-10-22T21:04:44.000Z","size":301,"stargazers_count":16,"open_issues_count":0,"forks_count":9,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-09T23:17:28.689Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saltstack.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-28T06:18:04.000Z","updated_at":"2024-11-13T18:58:05.000Z","dependencies_parsed_at":"2024-06-19T05:30:59.876Z","dependency_job_id":"ac26f32b-054d-4a25-969e-627d8271e4bb","html_url":"https://github.com/saltstack/pytest-shell-utilities","commit_stats":{"total_commits":103,"total_committers":4,"mean_commits":25.75,"dds":"0.10679611650485432","last_synced_commit":"0631d415089fbaa535b24209fdf0aee629e89b76"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saltstack%2Fpytest-shell-utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saltstack%2Fpytest-shell-utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saltstack%2Fpytest-shell-utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saltstack%2Fpytest-shell-utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saltstack","download_url":"https://codeload.github.com/saltstack/pytest-shell-utilities/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125593,"owners_count":21051771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:34:29.499Z","updated_at":"2025-04-09T23:17:34.311Z","avatar_url":"https://github.com/saltstack.png","language":"Python","readme":".. image:: https://img.shields.io/github/actions/workflow/status/saltstack/pytest-shell-utilities/testing.yml?style=plastic\u0026branch=main\n   :target: https://github.com/saltstack/pytest-shell-utilities/actions/workflows/testing.yml\n   :alt: CI\n\n.. image:: https://readthedocs.org/projects/pytest-shell-utilities/badge/?style=plastic\n   :target: https://pytest-shell-utilities.readthedocs.io\n   :alt: Docs\n\n\n.. image:: https://img.shields.io/codecov/c/github/saltstack/pytest-shell-utilities?style=plastic\u0026token=ctdrjPj4mc\n   :target: https://codecov.io/gh/saltstack/pytest-shell-utilities\n   :alt: Codecov\n\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-shell-utilities?style=plastic\n   :target: https://pypi.org/project/pytest-shell-utilities\n   :alt: Python Versions\n\n\n.. image:: https://img.shields.io/pypi/wheel/pytest-shell-utilities?style=plastic\n   :target: https://pypi.org/project/pytest-shell-utilities\n   :alt: Python Wheel\n\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=plastic\n   :target: https://github.com/psf/black\n   :alt: Code Style: black\n\n\n.. image:: https://img.shields.io/pypi/l/pytest-shell-utilities?style=plastic\n   :alt: PyPI - License\n\n\n..\n   include-starts-here\n\n==============================\nWhat is Pytest Shell Utilities\n==============================\n\n   \"When in doubt, shell out\"\n\n   -- Thomas S. Hatch\n\n\nThis pytest plugin was extracted from `pytest-salt-factories`_.\nIf provides a basic fixture ``shell`` which basically uses ``subprocess.Popen``\nto run commands against the running system on a shell while providing a nice\nassert'able return class.\n\n.. _pytest-salt-factories: https://github.com/saltstack/pytest-salt-factories\n\n\nInstall\n=======\n\nInstalling ``pytest-shell-utilities`` is as simple as:\n\n.. code-block:: bash\n\n   python -m pip install pytest-shell-utilities\n\n\nAnd, that's honestly it.\n\n\nUsage\n=====\n\nOnce installed, you can now use the ``shell`` fixture to run some commands and assert against the\noutcome.\n\n.. code-block:: python\n\n   def test_assert_good_exitcode(shell):\n\n       ret = shell.run(\"exit\", \"0\")\n       assert ret.returncode == 0\n\n\n   def test_assert_bad_exitcode(shell):\n\n       ret = shell.run(\"exit\", \"1\")\n       assert ret.returncode == 1\n\n\n\nIf the command outputs parseable JSON, the ``shell`` fixture can attempt loading that output as\nJSON which allows for asserting against the JSON loaded object.\n\n\n.. code-block:: python\n\n   def test_against_json_output(shell):\n       d = {\"a\": \"a\", \"b\": \"b\"}\n       ret = shell.run(\"echo\", json.dumps(d))\n       assert ret.data == d\n\n\nAdditionally, the return object's ``.stdout`` and ``.stderr`` can be line matched using\n`pytest.pytester.LineMatcher`_:\n\n.. code-block:: python\n\n   MARY_HAD_A_LITTLE_LAMB = \"\"\"\\\n   Mary had a little lamb,\n   Its fleece was white as snow;\n   And everywhere that Mary went\n   The lamb was sure to go.\n   \"\"\"\n\n\n   def test_matcher_attribute(shell):\n       ret = shell.run(\"echo\", MARY_HAD_A_LITTLE_LAMB)\n       ret.stdout.matcher.fnmatch_lines_random(\n           [\n               \"*had a little*\",\n               \"Its fleece was white*\",\n               \"*Mary went\",\n               \"The lamb was sure to go.\",\n           ]\n       )\n\n\n.. _pytest.pytester.LineMatcher: https://docs.pytest.org/en/stable/reference.html#pytest.pytester.LineMatcher\n\n..\n   include-ends-here\n\nDocumentation\n=============\n\nThe full documentation can be seen `here \u003chttps://pytest-shell-utilities.readthedocs.io\u003e`_.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaltstack%2Fpytest-shell-utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaltstack%2Fpytest-shell-utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaltstack%2Fpytest-shell-utilities/lists"}