// Run test coverage analysis, identify missed and partial lines, and write tests to improve coverage. Use this when the user asks to check coverage, improve coverage, or write tests for uncovered code. This skill detects both completely missed lines and partially covered lines (executed but missing branch coverage) to match Codecov analysis.
| name | coverage |
| description | Run test coverage analysis, identify missed and partial lines, and write tests to improve coverage. Use this when the user asks to check coverage, improve coverage, or write tests for uncovered code. This skill detects both completely missed lines and partially covered lines (executed but missing branch coverage) to match Codecov analysis. |
This skill guides you through analyzing test coverage and systematically improving it by writing targeted tests.
if branch was tested, not the else)Traditional coverage annotate cannot detect partial lines. This skill uses XML-based analysis to match what Codecov shows, ensuring agents can target the same gaps that appear in PR reviews.
Generate coverage XML report with branch coverage enabled:
uv run pytest -q --maxfail=1 \
--cov=sleap_io --cov-branch \
--cov-report=xml:coverage.xml
This creates coverage.xml with full branch coverage data.
Use the bundled script to summarize coverage gaps. The script is located at .claude/skills/coverage/scripts/cov_summary.py within this skill.
uv run python scripts/cov_summary.py --source coverage.xml --format md
uv run python scripts/cov_summary.py --source coverage.xml --only-pr-diff-lines --format md
uv run python scripts/cov_summary.py --source coverage.xml --only-changed --format md
The output shows a table with:
Example output:
| File | Missed | Partial |
| --- | --- | --- |
| io/coco.py | 122-124,518 | 82,84,87,121,279 |
| io/leap.py | — | 105,109,148 |
This means:
io/coco.py lines 122-124, 518 were never executedio/coco.py lines 82, 84, 87, 121, 279 executed but didn't cover all branchesio/leap.py has no missed lines, but lines 105, 109, 148 need branch coverageFor each file with gaps:
# Read the specific file to understand the uncovered code
Read io/coco.py
Focus on the line numbers from the coverage report. Look for:
if/else, and/or, try/except, ternary operatorsFor each gap identified:
Determine what conditions trigger the uncovered code
Find or create appropriate test fixtures
tests/fixtures/ for existing dataWrite focused tests
# Covers line 122: error handling for invalid input)Verify improvement
Coverage report shows:
io/slp.py | 1134,1244 | —
Action:
io/slp.py lines around 1134 and 1244test_load_corrupt_slp_file_raises_error()Coverage report shows:
model/labels.py | — | 338,376,550
Action:
model/labels.py line 338:
if video_path and video_path.exists():
test_labels_with_missing_video_path()video_path is None or doesn't existWhen working on a PR, focus only on lines you changed:
# 1. Run coverage
uv run pytest -q --maxfail=1 --cov=sleap_io --cov-branch --cov-report=xml:coverage.xml
# 2. Filter to PR lines only
uv run python scripts/cov_summary.py --source coverage.xml --only-pr-diff-lines --format md
If output shows:
✅ No uncovered lines found.
Great! Your PR has full coverage of all new/modified lines.
--only-pr-diff-lines)The script supports multiple formats:
--format text: Simple list (default)--format md: Markdown table (recommended for readability)--format json: Machine-readable with detailed branch info--format gh-annotations: GitHub workflow annotationsRun the pytest command with --cov-report=xml:coverage.xml
The --only-pr-diff-lines option requires gh CLI. Install with brew install gh or use --only-changed instead.
Ensure relative_files = true is set in [tool.coverage.run] section of pyproject.toml
The coverage workflow is integrated into CI at .github/workflows/ci.yml. On PRs, GitHub Actions automatically:
.claude/skills/coverage/scripts/cov_summary.py.claude/commands/coverage.mdscripts/cov_summary.pypyproject.toml [tool.coverage.*] sections