pytest-shell-utilities


Namepytest-shell-utilities JSON
Version 1.9.7 PyPI version JSON
download
home_pagehttps://github.com/saltstack/pytest-shell-utilities
SummaryPytest plugin to simplify running shell commands against the system
upload_time2024-10-22 21:07:20
maintainerNone
docs_urlNone
authorPedro Algarvio
requires_python>=3.8
licenseApache Software License 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            .. image:: https://img.shields.io/github/actions/workflow/status/saltstack/pytest-shell-utilities/testing.yml?style=plastic&branch=main
   :target: https://github.com/saltstack/pytest-shell-utilities/actions/workflows/testing.yml
   :alt: CI

.. image:: https://readthedocs.org/projects/pytest-shell-utilities/badge/?style=plastic
   :target: https://pytest-shell-utilities.readthedocs.io
   :alt: Docs


.. image:: https://img.shields.io/codecov/c/github/saltstack/pytest-shell-utilities?style=plastic&token=ctdrjPj4mc
   :target: https://codecov.io/gh/saltstack/pytest-shell-utilities
   :alt: Codecov


.. image:: https://img.shields.io/pypi/pyversions/pytest-shell-utilities?style=plastic
   :target: https://pypi.org/project/pytest-shell-utilities
   :alt: Python Versions


.. image:: https://img.shields.io/pypi/wheel/pytest-shell-utilities?style=plastic
   :target: https://pypi.org/project/pytest-shell-utilities
   :alt: Python Wheel


.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=plastic
   :target: https://github.com/psf/black
   :alt: Code Style: black


.. image:: https://img.shields.io/pypi/l/pytest-shell-utilities?style=plastic
   :alt: PyPI - License


..
   include-starts-here

==============================
What is Pytest Shell Utilities
==============================

   "When in doubt, shell out"

   -- Thomas S. Hatch


This pytest plugin was extracted from `pytest-salt-factories`_.
If provides a basic fixture ``shell`` which basically uses ``subprocess.Popen``
to run commands against the running system on a shell while providing a nice
assert'able return class.

.. _pytest-salt-factories: https://github.com/saltstack/pytest-salt-factories


Install
=======

Installing ``pytest-shell-utilities`` is as simple as:

.. code-block:: bash

   python -m pip install pytest-shell-utilities


And, that's honestly it.


Usage
=====

Once installed, you can now use the ``shell`` fixture to run some commands and assert against the
outcome.

.. code-block:: python

   def test_assert_good_exitcode(shell):

       ret = shell.run("exit", "0")
       assert ret.returncode == 0


   def test_assert_bad_exitcode(shell):

       ret = shell.run("exit", "1")
       assert ret.returncode == 1



If the command outputs parseable JSON, the ``shell`` fixture can attempt loading that output as
JSON which allows for asserting against the JSON loaded object.


.. code-block:: python

   def test_against_json_output(shell):
       d = {"a": "a", "b": "b"}
       ret = shell.run("echo", json.dumps(d))
       assert ret.data == d


Additionally, the return object's ``.stdout`` and ``.stderr`` can be line matched using
`pytest.pytester.LineMatcher`_:

.. code-block:: python

   MARY_HAD_A_LITTLE_LAMB = """\
   Mary had a little lamb,
   Its fleece was white as snow;
   And everywhere that Mary went
   The lamb was sure to go.
   """


   def test_matcher_attribute(shell):
       ret = shell.run("echo", MARY_HAD_A_LITTLE_LAMB)
       ret.stdout.matcher.fnmatch_lines_random(
           [
               "*had a little*",
               "Its fleece was white*",
               "*Mary went",
               "The lamb was sure to go.",
           ]
       )


.. _pytest.pytester.LineMatcher: https://docs.pytest.org/en/stable/reference.html#pytest.pytester.LineMatcher

..
   include-ends-here

Documentation
=============

The full documentation can be seen `here <https://pytest-shell-utilities.readthedocs.io>`_.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/saltstack/pytest-shell-utilities",
    "name": "pytest-shell-utilities",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Pedro Algarvio",
    "author_email": "pedro@algarvio.me",
    "download_url": "https://files.pythonhosted.org/packages/f9/de/6b4060bef2b650f87e01c3b5f2d0ee41f0b49f4bd903253941959fac08d2/pytest_shell_utilities-1.9.7.tar.gz",
    "platform": "unix",
    "description": ".. image:: https://img.shields.io/github/actions/workflow/status/saltstack/pytest-shell-utilities/testing.yml?style=plastic&branch=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&token=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 <https://pytest-shell-utilities.readthedocs.io>`_.\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "Pytest plugin to simplify running shell commands against the system",
    "version": "1.9.7",
    "project_urls": {
        "Documentation": "https://pytest-shell-utilities.readthedocs.io",
        "Homepage": "https://github.com/saltstack/pytest-shell-utilities",
        "Source": "https://github.com/saltstack/pytest-shell-utilities",
        "Tracker": "https://github.com/saltstack/pytest-shell-utilities/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "df3d09b2335b10f6a292a8c99907634655acbe0054850934574c904cab172a86",
                "md5": "7d72de76787ee906229fba03522cdd26",
                "sha256": "e9975718160d9d35c715e0b349ddb78afb43c810ac5c98a6d0714462c0456eb6"
            },
            "downloads": -1,
            "filename": "pytest_shell_utilities-1.9.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7d72de76787ee906229fba03522cdd26",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 28812,
            "upload_time": "2024-10-22T21:07:18",
            "upload_time_iso_8601": "2024-10-22T21:07:18.946340Z",
            "url": "https://files.pythonhosted.org/packages/df/3d/09b2335b10f6a292a8c99907634655acbe0054850934574c904cab172a86/pytest_shell_utilities-1.9.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f9de6b4060bef2b650f87e01c3b5f2d0ee41f0b49f4bd903253941959fac08d2",
                "md5": "0f62701fac736b6e4c26b0042ab64d66",
                "sha256": "84a2283333925b43780509ccfd3d5be0d7db243b7414b89f1b63954bbcc9d3ec"
            },
            "downloads": -1,
            "filename": "pytest_shell_utilities-1.9.7.tar.gz",
            "has_sig": false,
            "md5_digest": "0f62701fac736b6e4c26b0042ab64d66",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 81231,
            "upload_time": "2024-10-22T21:07:20",
            "upload_time_iso_8601": "2024-10-22T21:07:20.207439Z",
            "url": "https://files.pythonhosted.org/packages/f9/de/6b4060bef2b650f87e01c3b5f2d0ee41f0b49f4bd903253941959fac08d2/pytest_shell_utilities-1.9.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-22 21:07:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "saltstack",
    "github_project": "pytest-shell-utilities",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "pytest-shell-utilities"
}
        
Elapsed time: 0.38283s