coverage-sh


Namecoverage-sh JSON
Version 0.4.3 PyPI version JSON
download
home_page
SummaryA Coverage.py plugin to measure code coverage of shell scripts from python.
upload_time2024-03-12 20:39:41
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords bash coverage plugin sh shell
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Coverage.sh

[![PyPI - Version](https://img.shields.io/pypi/v/coverage-sh?color=blue)](https://pypi.org/project/coverage-sh/)
[![PyPI - Status](https://img.shields.io/pypi/status/coverage-sh)](https://github.com/lackhove/coverage-sh/blob/main/pyproject.toml)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/coverage-sh)](https://github.com/lackhove/coverage-sh/blob/main/pyproject.toml)
[![PyPI - License](https://img.shields.io/pypi/l/coverage-sh)](https://github.com/lackhove/coverage-sh/blob/main/LICENSE.txt)
![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/lackhove/f16009049fe5091e6d750a7bb7b4d68a/raw/covbadge.json)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/mitsuhiko/rye/main/artwork/badge.json)](https://rye-up.com)

A  [Coverage.py](https://github.com/nedbat/coveragepy) plugin to measure code coverage of shell (sh or bash) scripts
executed from python.

## Installation

```shell
pip install coverage-sh
```

## Usage

In your `pyproject.toml`, set

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

and run

```shell
coverage run main.py
coverage combine
coverage html
```

to measure coverage of all shell scripts executed via
the [subprocess](https://docs.python.org/3/library/subprocess.html) module, e.g.:

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

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

![coverage.sh report screenshot](doc/media/screenshot_html-report.png)

## 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

```toml
[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](https://github.com/pytest-dev/pytest-cov) but works with
starting pytest from coverage , e.g.:

```bash
coverage run -m pytest arg1 arg2 arg3
```

## License

Licensed under the [MIT License](LICENSE.txt).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "coverage-sh",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "bash,coverage,plugin,sh,shell",
    "author": "",
    "author_email": "Kilian Lackhove <kilian@lackhove.de>",
    "download_url": "https://files.pythonhosted.org/packages/33/f1/ca7428d0c9a32f004ebf214dd26f4bc7df42f8ab42c12841fe4853f39096/coverage_sh-0.4.3.tar.gz",
    "platform": null,
    "description": "# Coverage.sh\n\n[![PyPI - Version](https://img.shields.io/pypi/v/coverage-sh?color=blue)](https://pypi.org/project/coverage-sh/)\n[![PyPI - Status](https://img.shields.io/pypi/status/coverage-sh)](https://github.com/lackhove/coverage-sh/blob/main/pyproject.toml)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/coverage-sh)](https://github.com/lackhove/coverage-sh/blob/main/pyproject.toml)\n[![PyPI - License](https://img.shields.io/pypi/l/coverage-sh)](https://github.com/lackhove/coverage-sh/blob/main/LICENSE.txt)\n![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/lackhove/f16009049fe5091e6d750a7bb7b4d68a/raw/covbadge.json)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/mitsuhiko/rye/main/artwork/badge.json)](https://rye-up.com)\n\nA  [Coverage.py](https://github.com/nedbat/coveragepy) plugin to measure code coverage of shell (sh or bash) scripts\nexecuted from python.\n\n## Installation\n\n```shell\npip install coverage-sh\n```\n\n## Usage\n\nIn your `pyproject.toml`, set\n\n```toml\n[tool.coverage.run]\nplugins = [\"coverage_sh\"]\n```\n\nand run\n\n```shell\ncoverage run main.py\ncoverage combine\ncoverage html\n```\n\nto measure coverage of all shell scripts executed via\nthe [subprocess](https://docs.python.org/3/library/subprocess.html) module, e.g.:\n\n```python\nsubprocess.run([\"bash\", \"test.sh\"])\n```\n\nThe resulting coverage is then displayed alongside the coverage of the python files:\n\n![coverage.sh report screenshot](doc/media/screenshot_html-report.png)\n\n## Caveats\n\nThe plugin works by patching the `subprocess.Popen` class to set the \"ENV\" and \"BASH_ENV\" environment variables before\nexecution, to source a helper script which enables tracing. This approach comes with a few caveats:\n\n- It will only cover shell scripts that are executed via the subprocess module.\n- Only bash and sh are supported\n\n## Cover-Always Mode\n\nWhen using the subprocess modue is not an option, coverage-sh can operate in \"cover-always-mode\", which is activated by\nsetting\n\n```toml\n[tool.coverage.coverage_sh]\ncover_always = true\n```\n\nin the `pyproject.toml`. In this mode, Coverage.sh will not respect the `coverage.start()` and `coverage.stop()` calls\nand instead cover every shell script executed after the plugin gets loaded until the main process is finished.\nThis mode is also incompatible with the popular [pytest-cov](https://github.com/pytest-dev/pytest-cov) but works with\nstarting pytest from coverage , e.g.:\n\n```bash\ncoverage run -m pytest arg1 arg2 arg3\n```\n\n## License\n\nLicensed under the [MIT License](LICENSE.txt).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A  Coverage.py plugin to measure code coverage of shell scripts from python.",
    "version": "0.4.3",
    "project_urls": {
        "homepage": "https://github.com/lackhove/coverage-sh"
    },
    "split_keywords": [
        "bash",
        "coverage",
        "plugin",
        "sh",
        "shell"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f2db2366880263e233142fef4e8a4738a28e58a0c30477349b187e29ea4ee49c",
                "md5": "5dc4bdae766901e0bda8ffdf04706e62",
                "sha256": "d005ac13c724cde4038e20e291b68cb3e2291efad3b8a53c63e752a6ed7c8edd"
            },
            "downloads": -1,
            "filename": "coverage_sh-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5dc4bdae766901e0bda8ffdf04706e62",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7122,
            "upload_time": "2024-03-12T20:39:40",
            "upload_time_iso_8601": "2024-03-12T20:39:40.308375Z",
            "url": "https://files.pythonhosted.org/packages/f2/db/2366880263e233142fef4e8a4738a28e58a0c30477349b187e29ea4ee49c/coverage_sh-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33f1ca7428d0c9a32f004ebf214dd26f4bc7df42f8ab42c12841fe4853f39096",
                "md5": "2af907990ecb4fbf0147c58cdb5bb81b",
                "sha256": "8ef29a82e44544101b8b524f2e2600a6daef74be086af5392f1dca304e8e2d82"
            },
            "downloads": -1,
            "filename": "coverage_sh-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2af907990ecb4fbf0147c58cdb5bb81b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 79102,
            "upload_time": "2024-03-12T20:39:41",
            "upload_time_iso_8601": "2024-03-12T20:39:41.914676Z",
            "url": "https://files.pythonhosted.org/packages/33/f1/ca7428d0c9a32f004ebf214dd26f4bc7df42f8ab42c12841fe4853f39096/coverage_sh-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 20:39:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lackhove",
    "github_project": "coverage-sh",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "coverage-sh"
}
        
Elapsed time: 1.25939s