diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-31 12:31:35 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-31 12:31:35 -0500 |
| commit | af478a42b18c4d5e0712c4cb43036126d36c56b5 (patch) | |
| tree | 5ef37e4f4c0e1f749e1d3506dde4147036660854 /languages/python/claude/rules/python-testing.md | |
| parent | ddf48dc7ac780da1aacdff4e03f1d7da255b8f39 (diff) | |
| download | rulesets-af478a42b18c4d5e0712c4cb43036126d36c56b5.tar.gz rulesets-af478a42b18c4d5e0712c4cb43036126d36c56b5.zip | |
feat(python): add coverage-summary to the Python bundle
Second language in the coverage-summary fan-out, after the Elisp pilot. Same kernel: a module no test imports never appears in coverage.py's report, so a line-weighted total skips it silently and the suite looks healthier than it is. This counts every source file on disk that's absent from the report as 0% and weights the project number by file, so untested modules stay visible.
The script at languages/python/claude/scripts/coverage-summary.py parses coverage.py's JSON (files[path].summary.covered_lines / num_statements), resolves report paths against the report's directory since coverage records them relative to where it ran, and recurses the source dir for *.py. Unlike the Elisp version it doesn't print a per-file table, because coverage.py's own coverage report already does. The script adds the missing-file accounting that report lacks. It uses only the standard library, parsing the report rather than importing coverage.
The Python run confirmed the plumbing from the pilot is genuinely generic. install-lang and sync deliver the script and the project-owned coverage-makefile.txt with no Python-specific code. The one gap I had to close: the Python bundle shipped without a gitignore-add.txt, so the .claude/ footprint wasn't ignored and the script would have been committable. Added one mirroring the Elisp footprint plus Python artifacts (__pycache__, .coverage, coverage.json). make test gained a languages/*/tests/test_*.py discovery path alongside the existing Elisp ERT one.
Tests: 12 pytest covering the parser, the file-weighted number, and the missing-file detection including subpackage recursion, plus an install-lang check that the script lands in the gitignored footprint. I proved it against a report matching coverage.py's documented schema and the CLI end to end, but not against a live coverage json run, because coverage.py isn't installed in this repo's env. The first project to adopt it should sanity-check against a real report.
Diffstat (limited to 'languages/python/claude/rules/python-testing.md')
| -rw-r--r-- | languages/python/claude/rules/python-testing.md | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/languages/python/claude/rules/python-testing.md b/languages/python/claude/rules/python-testing.md index 4edde35..dedcce4 100644 --- a/languages/python/claude/rules/python-testing.md +++ b/languages/python/claude/rules/python-testing.md @@ -82,6 +82,22 @@ generation in-process. See `testing.md` § Combinatorial Coverage for the general rule and when to skip. +## Measuring Coverage — `make coverage-summary` + +The bundle ships a coverage summary at `.claude/scripts/coverage-summary.py` +and a Makefile fragment (`coverage-makefile.txt`) with `coverage` and +`coverage-summary` targets. After `make coverage` runs the suite under +coverage.py and writes a JSON report, `make coverage-summary` prints a +file-weighted project number and the source files no test imported. + +The number to watch is that missing-file count. A module no test imports never +appears in coverage.py's report, so a line-weighted total skips it silently and +the suite looks healthier than it is. The summary counts every `*.py` under the +source dir that's absent from the report as 0%, so an untested module drags the +project number down where you can see it. It doesn't reimplement the per-file +table — `coverage report` already prints that. Copy the fragment's targets into +your own Makefile to adopt it; the bundle never edits your Makefile. + ## Mocking Guidelines ### Mock these (external boundaries): |
