Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

coverage-py-analysis

БесплатноБез исполняемых скриптовНе проверен

Use for any question or task about Python code coverage with pytest or unittest, including quick how-to questions, a CI gate on a minimum, and coverage that…

testlandот testland★ 18 звёзд на GitHub

Об этом скилле

coverage-py-analysis

Overview

Per coveragepy-docs:

"Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not."

The tool is the de facto Python coverage solution; pytest's pytest-cov plugin is a thin convenience wrapper around it. As of the source fetch on 2026-05-05, "Current version is 7.13.5 (March 2026), supporting Python 3.10-3.15 alpha and PyPy3" (coveragepy-docs).

When to use

  • The project tests with pytest, unittest, or nose, and the team needs PR-time coverage signal.
  • A SaaS coverage dashboard (Codecov, Coveralls, Codacy) consumes LCOV or Cobertura - both are first-party output formats.
  • A multi-language project (Python + JS + Java) needs per-language coverage in a unified format (LCOV).

Step 1 - Install + replace python with coverage run

pip install coverage[toml]

[toml] is needed only for older Python (<3.11); newer ones include TOML parsing in stdlib.

Per coveragepy-docs:

"Replace your normal python command with this tool (e.g., python something.py becomes coverage run something.py)."

In practice, run pytest under coverage:

coverage run -m pytest
coverage report

Or via pytest-cov:

pytest --cov=src --cov-branch --cov-report=term-missing --cov-report=xml --cov-report=lcov

Step 2 - Enable branch coverage

Per coveragepy-docs, coverage.py defaults to statement coverage (line coverage). Branch coverage requires opt-in:

coverage run --branch -m pytest

Or in .coveragerc:

[run]
branch = True

Branch coverage catches the case where every line is executed but not every condition arm - if x and y where only the true branch is tested.

Step 3 - Author .coveragerc

The canonical config (.coveragerc or [tool.coverage] in pyproject.toml):

[run]
source = src
branch = True
parallel = True
omit =
    */tests/*
    */migrations/*
    */conftest.py

[report]
fail_under = 80
show_missing = True
skip_covered = False
exclude_lines =
    pragma: no cover
    raise NotImplementedError
    if __name__ == .__main__.:

[xml]
output = coverage.xml

[html]
directory = htmlcov

[lcov]
output = coverage.lcov

[json]
output = coverage.json

Per coveragepy-docs, the four key [run] settings:

Setting Use
source Restricts coverage to specific paths (avoids inflating from third-party).
branch Enables branch coverage (Step 2).
omit Excludes files (tests, migrations, generated code).
fail_under Fails coverage report if the total drops below the threshold.

exclude_lines patterns let the team mark unreachable / not-meant-to-be-tested code with magic comments (# pragma: no cover) and sentinel patterns like raise NotImplementedError.

Step 4 - Combine parallel runs

Pytest-xdist runs tests across multiple processes; each process writes its own .coverage.<host>.<pid>.<rand> file. Per coveragepy-docs, coverage combine merges them:

coverage run --parallel -m pytest -n auto
coverage combine
coverage report
coverage xml
coverage lcov

--parallel (or parallel = True in .coveragerc) makes coverage write per-process files instead of overwriting .coverage. coverage combine then merges them into the final .coverage.

Without combine, only the last process's data survives - the most common new-user mistake.

Step 5 - Pick the output format

Per coveragepy-docs, coverage.py emits five formats:

Command Output Use
coverage report Terminal text CI log readability + dev loop.
coverage html htmlcov/index.html Human review with per-line drill-down.
coverage xml coverage.xml (Cobertura format) Jenkins, Azure DevOps; cross-tool aggregation.
coverage lcov coverage.lcov Codecov, Coveralls, cross-tool diffing.
coverage json coverage.json Programmatic post-processing.

A typical CI emits xml + lcov + report:

coverage xml      # for Jenkins
coverage lcov     # for Codecov
coverage report   # for the CI log

Step 6 - coverage report --fail-under

For a self-contained gate (without external scripting):

coverage report --fai
Полный SKILL.md на GitHub

Установить coverage-py-analysis в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.tessl-plugin/plugin.json

FAQ

Что делает скилл coverage-py-analysis?

Use for any question or task about Python code coverage with pytest or unittest, including quick how-to questions, a CI gate on a minimum, and coverage that drops when tests run in parallel with xdist: coverage run, branch coverage, combining parallel data, .coveragerc source, omit and fail_under, and terminal, HTML, Cobertura XML, LCOV or JSON reports for CI.

Как установить скилл coverage-py-analysis?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл coverage-py-analysis запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить coverage-py-analysis с