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 Rye

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.4.5.tar.gz (79.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: coverage_sh-0.4.5.tar.gz
  • Upload date:
  • Size: 79.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for coverage_sh-0.4.5.tar.gz
Algorithm Hash digest
SHA256 583de924d83bb57b03b096bef606bdcf9f811d76bc1acbe2c24a93192f1ec0c2
MD5 700528744d12dc85f1ff6b4616827fcb
BLAKE2b-256 7f7c57827ab08be247d19cb233854933ea8b500aef53a960e4277527d207128a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coverage_sh-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for coverage_sh-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 21247c7e7985f11d4ef28661c83a646679da353b7bb5ce0b41465fae76e2cba2
MD5 0e2bbf58e9a5524366313b5c4295daef
BLAKE2b-256 594a1223abdd8c98340f7053bf3170fd471c27f3dc9307c05dd8b3f7b255277f

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