Skip to content

Commit ac83402

Browse files
authored
chore: use coverage run instead of pytest --cov (#3847)
* chore: improve code coverage reporting * update after_n_builds * fix: use `coverage run` instead of `pytest --cov` for accurate import-time coverage The pytest11 entry point (`zarr = "zarr.testing"`) imports 76 zarr modules during plugin loading, before pytest-cov starts measuring. This caused all module-level code (class definitions, imports, decorators) to appear uncovered, dropping reported coverage well below actual test coverage. `coverage run -m pytest` starts tracing before any imports, resolving the issue. * Revert changes * Revert change
1 parent 2dc4036 commit ac83402

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

.github/workflows/gpu_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ jobs:
7272
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
7373
with:
7474
token: ${{ secrets.CODECOV_TOKEN }}
75+
flags: gpu
7576
verbose: true # optional (default = false)

.github/workflows/hypothesis.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
uses: codecov/codecov-action@v5
8282
with:
8383
token: ${{ secrets.CODECOV_TOKEN }}
84+
flags: tests
8485
verbose: true # optional (default = false)
8586

8687
- name: Generate and publish the report

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
uses: codecov/codecov-action@v5
7272
with:
7373
token: ${{ secrets.CODECOV_TOKEN }}
74+
flags: tests
7475
verbose: true # optional (default = false)
7576

7677
test-upstream-and-min-deps:
@@ -110,6 +111,7 @@ jobs:
110111
uses: codecov/codecov-action@v5
111112
with:
112113
token: ${{ secrets.CODECOV_TOKEN }}
114+
flags: tests
113115
verbose: true # optional (default = false)
114116

115117
doctests:

codecov.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@ coverage:
88
default:
99
target: auto
1010
threshold: 0.1
11+
flags:
12+
- tests
13+
flags:
14+
tests:
15+
paths:
16+
- src/
17+
carryforward: true
18+
gpu:
19+
paths:
20+
- src/
21+
carryforward: true
1122
codecov:
1223
notify:
13-
after_n_builds: 10 # Wait for all 10 reports before updating the status
24+
# 6 = test.yml: 3 (optional+ubuntu) + 2 (upstream + min_deps), hypothesis: 1
25+
after_n_builds: 6
1426
wait_for_ci: yes
1527
comment:
1628
layout: "diff, files"

pyproject.toml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ hooks.vcs.version-file = "src/zarr/_version.py"
155155
dependency-groups = ["test"]
156156

157157
[tool.hatch.envs.test.env-vars]
158-
# Required to test with a pytest plugin; see https://pytest-cov.readthedocs.io/en/latest/plugins.html
159-
COV_CORE_SOURCE = "src"
160-
COV_CORE_CONFIG = ".coveragerc"
161-
COV_CORE_DATAFILE = ".coverage.eager"
162158

163159
[[tool.hatch.envs.test.matrix]]
164160
python = ["3.12", "3.13", "3.14"]
@@ -175,13 +171,23 @@ matrix.deps.dependency-groups = [
175171
]
176172

177173
[tool.hatch.envs.test.scripts]
178-
run-coverage = "pytest --cov-config=pyproject.toml --cov=src --cov-append --cov-report xml --junitxml=junit.xml -o junit_family=legacy"
179-
run-coverage-html = "pytest --cov-config=pyproject.toml --cov=src --cov-append --cov-report html"
180-
run = "run-coverage --no-cov --ignore tests/benchmarks"
174+
run-coverage = [
175+
"coverage run --source=src -m pytest --junitxml=junit.xml -o junit_family=legacy {args:}",
176+
"coverage xml",
177+
]
178+
run-coverage-html = [
179+
"coverage run --source=src -m pytest {args:}",
180+
"coverage html",
181+
]
182+
run = "pytest --ignore tests/benchmarks"
181183
run-verbose = "run-coverage --verbose"
182184
run-mypy = "mypy src"
183-
run-hypothesis = "run-coverage -nauto --run-slow-hypothesis tests/test_properties.py tests/test_store/test_stateful*"
185+
run-hypothesis = [
186+
"coverage run --source=src -m pytest -nauto --run-slow-hypothesis tests/test_properties.py tests/test_store/test_stateful* {args:}",
187+
"coverage xml",
188+
]
184189
run-benchmark = "pytest --benchmark-enable tests/benchmarks"
190+
serve-coverage-html = "python -m http.server -d htmlcov 8000"
185191
list-env = "pip list"
186192

187193
[tool.hatch.envs.gputest]
@@ -195,8 +201,11 @@ features = ["gpu"]
195201
python = ["3.12", "3.13"]
196202

197203
[tool.hatch.envs.gputest.scripts]
198-
run-coverage = "pytest -m gpu --cov-config=pyproject.toml --cov=src --cov-report xml --junitxml=junit.xml -o junit_family=legacy --ignore tests/benchmarks"
199-
run = "run-coverage --no-cov"
204+
run-coverage = [
205+
"coverage run --source=src -m pytest -m gpu --junitxml=junit.xml -o junit_family=legacy --ignore tests/benchmarks {args:}",
206+
"coverage xml",
207+
]
208+
run = "pytest -m gpu --ignore tests/benchmarks"
200209

201210
[tool.hatch.envs.upstream]
202211
template = 'test'

0 commit comments

Comments
 (0)