Skip to content

Commit 0c84038

Browse files
committed
ci: add strict-no-cover to detect unnecessary coverage pragmas
Add strict-no-cover from pydantic to CI pipeline. This tool identifies `# pragma: no cover` comments on lines that are actually covered by tests, helping keep coverage pragmas accurate. Changes: - Add strict-no-cover as dev dependency (installed from git) - Add `pragma: lax no cover` to coverage exclude_lines for partial coverage - Add CI step to run strict-no-cover after coverage report (Linux only due to a Windows bug in the tool) - Pin coverage to <=7.13 (7.13.1 introduced a regression that breaks strict-no-cover by changing how source paths are reported in .coverage databases) - Remove relative_files=true from [tool.coverage.run] as it interferes with strict-no-cover path matching
1 parent 3cfdea0 commit 0c84038

File tree

3 files changed

+115
-98
lines changed

3 files changed

+115
-98
lines changed

.github/workflows/shared.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ jobs:
6262
uv run --frozen --no-sync coverage combine
6363
uv run --frozen --no-sync coverage report
6464
65+
- name: Check for unnecessary no cover pragmas
66+
if: runner.os != 'Windows'
67+
run: uv run --frozen --no-sync strict-no-cover
68+
6569
readme-snippets:
6670
runs-on: ubuntu-latest
6771
steps:

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ dev = [
6666
"pytest-pretty>=1.2.0",
6767
"inline-snapshot>=0.23.0",
6868
"dirty-equals>=0.9.0",
69-
"coverage[toml]>=7.13.1",
69+
"coverage[toml]>=7.10.7,<=7.13",
7070
"pillow>=12.0",
71+
"strict-no-cover",
7172
]
7273
docs = [
7374
"mkdocs>=1.6.1",
@@ -163,6 +164,7 @@ members = ["examples/clients/*", "examples/servers/*", "examples/snippets"]
163164

164165
[tool.uv.sources]
165166
mcp = { workspace = true }
167+
strict-no-cover = { git = "https://github.com/pydantic/strict-no-cover" }
166168

167169
[tool.pytest.ini_options]
168170
log_cli = true
@@ -198,7 +200,6 @@ branch = true
198200
patch = ["subprocess"]
199201
concurrency = ["multiprocessing", "thread"]
200202
source = ["src", "tests"]
201-
relative_files = true
202203
omit = [
203204
"src/mcp/client/__main__.py",
204205
"src/mcp/server/__main__.py",
@@ -215,6 +216,7 @@ ignore_errors = true
215216
precision = 2
216217
exclude_lines = [
217218
"pragma: no cover",
219+
"pragma: lax no cover",
218220
"if TYPE_CHECKING:",
219221
"@overload",
220222
"raise NotImplementedError",

0 commit comments

Comments
 (0)