Skip to main content

Pytest plugin to simplify running shell commands against the system

Project description

CI Docs Codecov Python Versions Python Wheel Code Style: black PyPI - License

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.

Install

Installing pytest-shell-utilities is as simple as:

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.

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.

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

Documentation

The full documentation can be seen here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-shell-utilities-1.0.0rc2.tar.gz (89.9 kB view details)

Uploaded Source

Built Distribution

pytest_shell_utilities-1.0.0rc2-py3-none-any.whl (44.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest-shell-utilities-1.0.0rc2.tar.gz.

File metadata

  • Download URL: pytest-shell-utilities-1.0.0rc2.tar.gz
  • Upload date:
  • Size: 89.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.8

File hashes

Hashes for pytest-shell-utilities-1.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 9d56b6b329e55ccf53fb0ead8b530f940e407ea326a38aba03f815d42e99f68c
MD5 78f78072c82f217eedec98f4896c79a1
BLAKE2b-256 a5ec07243b455f31db25ef7b586958e131d0d8bb324be11b1d948b0627ab3a3b

See more details on using hashes here.

File details

Details for the file pytest_shell_utilities-1.0.0rc2-py3-none-any.whl.

File metadata

  • Download URL: pytest_shell_utilities-1.0.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 44.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.8

File hashes

Hashes for pytest_shell_utilities-1.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 7dad5a0246d5e6dd772b0a006e9506d490f0e9aa8f19bf39a0611922d7afcb17
MD5 e607ac30d1604f31d9ee9e75b08d6a9c
BLAKE2b-256 45eae5a2a22e6bda5a3a356e7e04736691c2ec51dc8da0eab241803ec3ddc0bf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page