pytest-shell-utilities


Namepytest-shell-utilities JSON
Version 1.8.0 PyPI version JSON
download
home_pagehttps://github.com/saltstack/pytest-shell-utilities
SummaryPytest plugin to simplify running shell commands against the system
upload_time2023-07-02 20:36:52
maintainer
docs_urlNone
authorPedro Algarvio
requires_python>=3.7
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/workflow/status/saltstack/pytest-shell-utilities/CI/main?style=plastic
   :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": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Pedro Algarvio",
    "author_email": "pedro@algarvio.me",
    "download_url": "https://files.pythonhosted.org/packages/63/9d/9ce26090f104441d2441473c5802d07b127560261baf4ac78eb7fb8aeafa/pytest-shell-utilities-1.8.0.tar.gz",
    "platform": "unix",
    "description": ".. image:: https://img.shields.io/github/workflow/status/saltstack/pytest-shell-utilities/CI/main?style=plastic\n   :target: https://github.com/saltstack/pytest-shell-utilities/actions/workflows/testing.yml\n   :alt: CI\n\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.8.0",
    "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": "16acbcef186a3288516f8ac3aa2fef5fe03b5f9f669aaad6e87b3b591c76842e",
                "md5": "54082a8d8c26d1ccf214c2aa3b93234d",
                "sha256": "38d53bce755e9d9b4236ac86cc1ce90ef2485b401b422f736542d3d02144b8fa"
            },
            "downloads": -1,
            "filename": "pytest_shell_utilities-1.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "54082a8d8c26d1ccf214c2aa3b93234d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 28646,
            "upload_time": "2023-07-02T20:36:50",
            "upload_time_iso_8601": "2023-07-02T20:36:50.654784Z",
            "url": "https://files.pythonhosted.org/packages/16/ac/bcef186a3288516f8ac3aa2fef5fe03b5f9f669aaad6e87b3b591c76842e/pytest_shell_utilities-1.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "639d9ce26090f104441d2441473c5802d07b127560261baf4ac78eb7fb8aeafa",
                "md5": "c7f0ae17298e9d7a44b46df032b05ace",
                "sha256": "7f9a1aac43fad962da11e0ba1ae771eb3b84b73fc4bee94a8f563159231e1920"
            },
            "downloads": -1,
            "filename": "pytest-shell-utilities-1.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c7f0ae17298e9d7a44b46df032b05ace",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 80418,
            "upload_time": "2023-07-02T20:36:52",
            "upload_time_iso_8601": "2023-07-02T20:36:52.259384Z",
            "url": "https://files.pythonhosted.org/packages/63/9d/9ce26090f104441d2441473c5802d07b127560261baf4ac78eb7fb8aeafa/pytest-shell-utilities-1.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-02 20:36:52",
    "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.14714s