Know your gaps. Write the missing tests.
code-covered reads your coverage.json, walks the AST to understand context — exception handlers, branches, loops — then generates prioritized, ready-to-use test stubs. Not just what lines are missing. What tests to write.
Quick start
pip install code-covered
# Run tests with coverage JSON
pytest --cov=myapp --cov-report=json
# Find what you're missing
code-covered coverage.json
Example output
Coverage: 74.5% (35/47 lines)
Files analyzed: 1 (1 with gaps)
Missing tests: 4
[!!] CRITICAL: 2
[! ] HIGH: 2
Top suggestions:
1. [!!] test_validator_validate_input_handles_exception
In validate_input() lines 23-27
— when ValueError is raised
2. [!!] test_validator_parse_data_raises_error
In parse_data() lines 45-45 — raise ParseError
Generate stubs
# Write test stubs directly to a file
code-covered coverage.json -o tests/test_gaps.py
# Filter to critical gaps only
code-covered coverage.json --priority critical
# JSON output for CI pipelines
code-covered coverage.json --format json
# Show full test templates
code-covered coverage.json -v
More than a coverage report
It understands your code. Not just which lines are missing.
AST-aware context
Walks the source AST to understand what each uncovered block actually does — is it an exception handler? A branch condition? A loop body? The suggestion reflects the context.
Prioritized by risk
Critical first: exception handlers and raise statements that were never triggered. Then branches, then loops. The gaps most likely to break production surface at the top.
Zero dependencies
Pure Python stdlib. No heavy installs, no API calls, no runtime magic. Works anywhere pytest-cov produces a coverage.json. Install once, run anywhere.
Priority levels
Every gap is classified before it's surfaced.
Get started
Install & run
pip install code-covered
# Generate coverage.json
pytest --cov=myapp --cov-report=json
# Analyze gaps
code-covered coverage.json
# Verbose: show full templates
code-covered coverage.json -v Generate test stubs
# Write stubs to a file
code-covered coverage.json -o tests/test_missing.py
# Filter by priority
code-covered coverage.json --priority critical
code-covered coverage.json --priority high
# Limit output
code-covered coverage.json --limit 5 CI integration
# JSON output for scripts and pipelines
code-covered coverage.json --format json
# Exit codes
# 0 — success (gaps found or clean)
# 1 — error (file not found, parse error)
# Specify source root if paths are relative
code-covered coverage.json --source-root ./src Python API
from analyzer import find_coverage_gaps
# Find gaps programmatically
suggestions, warnings = find_coverage_gaps("coverage.json")
for s in suggestions:
print(f"{s.priority}: {s.test_name}")
print(f" Lines: {s.covers_lines}")
print(f" Template:\n{s.code_template}") How it works
Five steps from coverage report to ready-to-paste test stub.
Parse & map
Reads coverage.json from pytest-cov. Parses source files with stdlib ast to map every uncovered line back to the function, class, and block it lives in.
Detect & template
Classifies each gap — exception handler, branch, loop, raise statement — and generates a specific, context-aware test template with Arrange/Act/Assert scaffolding and setup hints.
Prioritize & emit
Ranks by risk and outputs to terminal, test stub files, or JSON for CI. Drop the generated stubs into your test suite and fill in the TODOs.