Skip to main content

A CLI tool that generates a Shields.io coverage badge and inserts it into your README.md automatically.

Project description

cov-badge

python-required coverage

A CLI tool that generates a Shields.io coverage badge and inserts it into your README.md automatically.

Installation

pip install cov-badge

Or with uv:

uv add --dev cov-badge

Usage

Run cov-badge from your project root after generating a coverage report:

# Generate coverage report (coverage.py example)
coverage run -m pytest
coverage json

# or using pytest-cov
pytest --cov=your_package --cov-report=json

# Insert or update badge in README.md
cov-badge

The tool will insert a badge like this into your README.md:

![coverage](https://img.shields.io/badge/coverage-95%25-green)

If a coverage badge already exists it will be updated in place. If not, it will be inserted after any existing badges, or directly after the main title (#).

Options

Option Short Description
--readme-file README file to update (default: README.md)
--json-file Coverage JSON file to read (default: coverage.json)
--percent-path Dot-separated path to the coverage value in the JSON file
--color-thresholds JSON string defining colour thresholds
--quiet -q Suppress output on success
--dry-run -d Print the badge string without writing to the README
--version -V Show version and exit
--help Show help and exit

Examples

Use a different README or JSON file:

cov-badge --readme-file MYREADME.md --json-file reports/coverage.json

Preview the badge without writing it:

cov-badge --dry-run

Use a custom path to the coverage value in the JSON:

cov-badge --percent-path meta.coverage

Override the colour thresholds:

cov-badge --color-thresholds '[[100, "brightgreen"], [80, "green"], [0, "red"]]'

Configuration

Options can be set via the command line, environment variables, a .env file, or pyproject.toml. They are applied in that priority order — command line takes precedence over everything else.

pyproject.toml

Add a [tool.cov-badge] section:

[tool.cov-badge]
readme_file = "README.md"
json_file = "coverage.json"
percent_path = ["totals", "percent_statements_covered_display"]
color_thresholds = [
    [100, "brightgreen"],
    [90, "green"],
    [70, "yellow"],
    [50, "orange"],
    [0, "red"],
]

Environment variables

All options can be set via environment variables prefixed with COV_BADGE_:

COV_BADGE_README_FILE=README.md
COV_BADGE_JSON_FILE=coverage.json
COV_BADGE_PERCENT_PATH='["totals", "percent_statements_covered_display"]'
COV_BADGE_COLOR_THRESHOLDS='[[100, "brightgreen"], [0, "red"]]'

.env file

The same variables can be set in a .env file in your project root:

COV_BADGE_README_FILE=README.md
COV_BADGE_JSON_FILE=coverage.json

Colour thresholds

The default thresholds are:

Coverage Colour
100% brightgreen
90–99% green
70–89% yellow
50–69% orange
0–49% red

Colours must be valid Shields.io named colours or hex codes. Thresholds can be supplied in any order. It is recommended to always include a 0 entry as a catch-all — if no zero entry is present, a warning will be issued and the lowest defined colour will be used as a fallback.

Custom JSON structure

By default cov-badge reads from the path ["totals", "percent_statements_covered_display"] in the JSON file, which matches the output of coverage.py. If your coverage tool produces a different JSON structure, you can specify a custom path.

For example, if your coverage.json looks like:

{
    "meta": {
        "coverage": 95
    }
}

Set the path via pyproject.toml:

[tool.cov-badge]
percent_path = ["meta", "coverage"]

Or via the CLI:

cov-badge --percent-path meta.coverage

CI usage

A typical GitHub Actions step after running your test suite:

- name: Generate coverage report
  run: |
    coverage run -m pytest
    coverage json

- name: Update coverage badge
  run: cov-badge

To suppress output in CI:

cov-badge --quiet

Requirements

  • Python 3.12+

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

cov_badge-0.1.1.tar.gz (106.8 kB view details)

Uploaded Source

Built Distribution

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

cov_badge-0.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file cov_badge-0.1.1.tar.gz.

File metadata

  • Download URL: cov_badge-0.1.1.tar.gz
  • Upload date:
  • Size: 106.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cov_badge-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6cb0b8609545494400d7985c4582ec7da2028043155d7289481bc87190b25127
MD5 89a6652f04bd49d21746bb87b6a64bd5
BLAKE2b-256 f9ed7445ff16f7e310757d813cf9fb7260594bb57bf070b709a2caec4e7db90d

See more details on using hashes here.

File details

Details for the file cov_badge-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cov_badge-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cov_badge-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d26be3c2bbad12d6d39fd98b67478bb1c0c8df32deb708c5cbfe072a3d1f956
MD5 570ec571cf701526c1408668c2219fc1
BLAKE2b-256 40e8e662b986adf8c2fbd1a49438c369de1461f39d802dc5d66be0dfeff75cdd

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