diff options
Diffstat (limited to 'languages/python/coverage-makefile.txt')
| -rw-r--r-- | languages/python/coverage-makefile.txt | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/languages/python/coverage-makefile.txt b/languages/python/coverage-makefile.txt new file mode 100644 index 0000000..5764120 --- /dev/null +++ b/languages/python/coverage-makefile.txt @@ -0,0 +1,46 @@ +# Python coverage — Makefile fragment + setup recommendation +# +# This file is owned by the project, not the rulesets bundle. The bundle never +# edits your Makefile. Copy the two targets below into your own Makefile (and +# adjust the variables at the top), then delete this file or keep it as a note. +# +# What you get: +# make coverage runs the test suite under coverage.py, writes a JSON +# report, and prints coverage.py's own per-file table +# make coverage-summary prints a file-weighted project number and — the point +# — every source file on disk that no test imported, +# counted as 0%. +# +# Why the summary matters: a module no test imports never appears in coverage.py's +# output, so a line-weighted total silently skips it. The summary weights by file +# and counts a missing file as 0%, so untested modules stay visible. It does not +# reimplement the per-file table — `coverage report` already prints that. +# +# --------------------------------------------------------------------------- +# Prerequisite: coverage.py +# +# pip install coverage # or pytest-cov, if you prefer the pytest plugin +# +# The summary script itself needs nothing beyond the standard library — it parses +# the JSON report, it does not import coverage. +# --------------------------------------------------------------------------- + +# Variables — adjust to your layout. +PYTHON ?= python3 +SOURCE_DIR ?= src +COVERAGE_FILE ?= coverage.json +# The summary script ships with the bundle under .claude/scripts/ (gitignored). +COVERAGE_SUMMARY ?= .claude/scripts/coverage-summary.py + +coverage: + @$(PYTHON) -m coverage run --source=$(SOURCE_DIR) -m pytest + @$(PYTHON) -m coverage json -o $(COVERAGE_FILE) + @$(PYTHON) -m coverage report + @$(MAKE) coverage-summary + +coverage-summary: + @if [ ! -f $(COVERAGE_FILE) ]; then \ + echo "[!] No coverage file at $(COVERAGE_FILE). Run 'make coverage' first."; \ + exit 1; \ + fi + @$(PYTHON) $(COVERAGE_SUMMARY) $(COVERAGE_FILE) $(SOURCE_DIR) $(CURDIR) |
