Skip to main content

A Coverage.py plugin to measure code coverage of shell scripts from python.

Project description

Coverage.sh

PyPI - Version PyPI - Status PyPI - Python Version PyPI - License Coverage Ruff uv

A Coverage.py plugin to measure code coverage of shell (sh or bash) scripts executed from python.

Installation

pip install coverage-sh

Usage

In your pyproject.toml, set

[tool.coverage.run]
plugins = ["coverage_sh"]

and run

coverage run main.py
coverage combine
coverage html

to measure coverage of all shell scripts executed via the subprocess module, e.g.:

subprocess.run(["bash", "test.sh"])

The resulting coverage is then displayed alongside the coverage of the python files:

coverage.sh report screenshot

Caveats

The plugin works by patching the subprocess.Popen class to set the "ENV" and "BASH_ENV" environment variables before execution, to source a helper script which enables tracing. This approach comes with a few caveats:

  • It will only cover shell scripts that are executed via the subprocess module.
  • Only bash and sh are supported

Cover-Always Mode

When using the subprocess modue is not an option, coverage-sh can operate in "cover-always-mode", which is activated by setting

[tool.coverage.coverage_sh]
cover_always = true

in the pyproject.toml. In this mode, Coverage.sh will not respect the coverage.start() and coverage.stop() calls and instead cover every shell script executed after the plugin gets loaded until the main process is finished. This mode is also incompatible with the popular pytest-cov but works with starting pytest from coverage , e.g.:

coverage run -m pytest arg1 arg2 arg3

License

Licensed under the MIT License.

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

coverage_sh-0.5.0.tar.gz (125.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coverage_sh-0.5.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file coverage_sh-0.5.0.tar.gz.

File metadata

  • Download URL: coverage_sh-0.5.0.tar.gz
  • Upload date:
  • Size: 125.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for coverage_sh-0.5.0.tar.gz
Algorithm Hash digest
SHA256 810efe53c72ddf9957a34b7f07b72786e7332179633bfa950f755fc2f2c8fd46
MD5 84c80998260c5f446521d1b63056e35f
BLAKE2b-256 b14ec7e1882933098eac00861235786c8d39e581fcdf68bc4643174f230076fc

See more details on using hashes here.

File details

Details for the file coverage_sh-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: coverage_sh-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for coverage_sh-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db0d1d953b07ddcd2200d7ff035069c0bbdffa87f9be5ce94dbe66cc9765a01c
MD5 f6c710ee13fafa8670d9be2414388da7
BLAKE2b-256 e3f95534a9d58af7fcf2eb72d1397cc672622a5194001fcb1c08b3e82d06c734

See more details on using hashes here.

Supported by

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