Skip to content

Commit 5b9e472

Browse files
raballewclaude
andcommitted
fix: use coverage combine with path mapping for accurate diff-cover
Per-package coverage.xml files stored source filenames relative to each package directory, making diff-cover unable to match them against git diff paths. This caused diff-cover to report artificially low coverage despite tests achieving 100% coverage on the changed lines. - Enable relative_files in coverage.run config - Add coverage.paths mapping so coverage combine can unify per-package paths into paths relative to the python/ workspace root - Move skip_empty to coverage.report where it belongs - Replace per-file diff-cover invocation with coverage combine followed by diff-cover on a single merged coverage.xml - Remove redundant PYTEST_ADDOPTS override from CI Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 43ccb52 commit 5b9e472

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

.github/workflows/python-tests.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ jobs:
117117
118118
- name: Run pytest
119119
working-directory: python
120-
env:
121-
PYTEST_ADDOPTS: "--cov --cov-report=xml"
122120
run: |
123121
make test
124122
125123
- name: Check coverage on changed lines
126124
if: github.event_name == 'pull_request'
127125
working-directory: python
128126
run: |
129-
coverage_files=$(find packages -name coverage.xml 2>/dev/null | sort)
130-
if [ -z "$coverage_files" ]; then
131-
echo "::error::No coverage.xml files found"
127+
coverage_data=$(find packages -name .coverage -type f 2>/dev/null | sort)
128+
if [ -z "$coverage_data" ]; then
129+
echo "::error::No .coverage data files found"
132130
exit 1
133131
fi
134-
uv run diff-cover $coverage_files --compare-branch=origin/${{ github.base_ref }} --fail-under=80
132+
uv run coverage combine $coverage_data
133+
uv run coverage xml -o combined-coverage.xml
134+
uv run diff-cover combined-coverage.xml --compare-branch=origin/${{ github.base_ref }} --fail-under=80
135135
136136
# https://github.com/orgs/community/discussions/26822
137137
pytest:

python/pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,17 @@ mosquitto = "mosquitto"
101101

102102
[tool.coverage.run]
103103
branch = true
104+
relative_files = true
104105
omit = ["conftest.py", "test_*.py", "*_test.py", "*_pb2.py", "*_pb2_grpc.py"]
106+
107+
[tool.coverage.report]
105108
skip_empty = true
106109

110+
[tool.coverage.paths]
111+
source = [
112+
"packages/*/",
113+
]
114+
107115
[tool.pytest.ini_options]
108116
addopts = "--capture=no --doctest-modules --cov --cov-report=html --cov-report=xml"
109117

0 commit comments

Comments
 (0)