coverage-sh


Namecoverage-sh JSON
Version 0.4.5 PyPI version JSON
download
home_pageNone
SummaryA Coverage.py plugin to measure code coverage of shell scripts from python.
upload_time2024-09-02 20:05:32
maintainerNone
docs_urlNone
authorNone
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": null,
    "name": "coverage-sh",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "bash, coverage, plugin, sh, shell",
    "author": null,
    "author_email": "Kilian Lackhove <kilian@lackhove.de>",
    "download_url": "https://files.pythonhosted.org/packages/7f/7c/57827ab08be247d19cb233854933ea8b500aef53a960e4277527d207128a/coverage_sh-0.4.5.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.5",
    "project_urls": {
        "homepage": "https://github.com/lackhove/coverage-sh"
    },
    "split_keywords": [
        "bash",
        " coverage",
        " plugin",
        " sh",
        " shell"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "594a1223abdd8c98340f7053bf3170fd471c27f3dc9307c05dd8b3f7b255277f",
                "md5": "0e2bbf58e9a5524366313b5c4295daef",
                "sha256": "21247c7e7985f11d4ef28661c83a646679da353b7bb5ce0b41465fae76e2cba2"
            },
            "downloads": -1,
            "filename": "coverage_sh-0.4.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0e2bbf58e9a5524366313b5c4295daef",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7213,
            "upload_time": "2024-09-02T20:05:30",
            "upload_time_iso_8601": "2024-09-02T20:05:30.919741Z",
            "url": "https://files.pythonhosted.org/packages/59/4a/1223abdd8c98340f7053bf3170fd471c27f3dc9307c05dd8b3f7b255277f/coverage_sh-0.4.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f7c57827ab08be247d19cb233854933ea8b500aef53a960e4277527d207128a",
                "md5": "700528744d12dc85f1ff6b4616827fcb",
                "sha256": "583de924d83bb57b03b096bef606bdcf9f811d76bc1acbe2c24a93192f1ec0c2"
            },
            "downloads": -1,
            "filename": "coverage_sh-0.4.5.tar.gz",
            "has_sig": false,
            "md5_digest": "700528744d12dc85f1ff6b4616827fcb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 79525,
            "upload_time": "2024-09-02T20:05:32",
            "upload_time_iso_8601": "2024-09-02T20:05:32.343877Z",
            "url": "https://files.pythonhosted.org/packages/7f/7c/57827ab08be247d19cb233854933ea8b500aef53a960e4277527d207128a/coverage_sh-0.4.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-02 20:05:32",
    "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: 0.35008s