From 2c623c769d41926e75f0505a5f90eb6067df8dd2 Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Mon, 30 Mar 2026 12:00:47 -0400 Subject: [PATCH 1/5] chore: improve code coverage reporting --- codecov.yml | 1 - pyproject.toml | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/codecov.yml b/codecov.yml index ef535fd8fe..745d1f503c 100644 --- a/codecov.yml +++ b/codecov.yml @@ -10,7 +10,6 @@ coverage: threshold: 0.1 codecov: notify: - after_n_builds: 10 # Wait for all 10 reports before updating the status wait_for_ci: yes comment: layout: "diff, files" diff --git a/pyproject.toml b/pyproject.toml index 8277c3f752..c69a3e4869 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -157,7 +157,7 @@ dependency-groups = ["test"] [tool.hatch.envs.test.env-vars] # Required to test with a pytest plugin; see https://pytest-cov.readthedocs.io/en/latest/plugins.html COV_CORE_SOURCE = "src" -COV_CORE_CONFIG = ".coveragerc" +COV_CORE_CONFIG = "pyproject.toml" COV_CORE_DATAFILE = ".coverage.eager" [[tool.hatch.envs.test.matrix]] @@ -175,8 +175,8 @@ matrix.deps.dependency-groups = [ ] [tool.hatch.envs.test.scripts] -run-coverage = "pytest --cov-config=pyproject.toml --cov=src --cov-append --cov-report xml --junitxml=junit.xml -o junit_family=legacy" -run-coverage-html = "pytest --cov-config=pyproject.toml --cov=src --cov-append --cov-report html" +run-coverage = "pytest --cov-config=pyproject.toml --cov=src --cov-report xml --junitxml=junit.xml -o junit_family=legacy" +run-coverage-html = "pytest --cov-config=pyproject.toml --cov=src --cov-report html" run = "run-coverage --no-cov --ignore tests/benchmarks" run-verbose = "run-coverage --verbose" run-mypy = "mypy src" From da174e3fc917bdb554887bc4a1adbb83eb27eb44 Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Mon, 30 Mar 2026 12:11:39 -0400 Subject: [PATCH 2/5] update after_n_builds --- .github/workflows/gpu_test.yml | 1 + .github/workflows/hypothesis.yaml | 1 + .github/workflows/test.yml | 2 ++ codecov.yml | 17 +++++++++++++++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gpu_test.yml b/.github/workflows/gpu_test.yml index 4fdffab057..d3aa03d2f6 100644 --- a/.github/workflows/gpu_test.yml +++ b/.github/workflows/gpu_test.yml @@ -72,4 +72,5 @@ jobs: uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1 with: token: ${{ secrets.CODECOV_TOKEN }} + flags: gpu verbose: true # optional (default = false) diff --git a/.github/workflows/hypothesis.yaml b/.github/workflows/hypothesis.yaml index 1ec6b4806d..a6a5ebbe6a 100644 --- a/.github/workflows/hypothesis.yaml +++ b/.github/workflows/hypothesis.yaml @@ -81,6 +81,7 @@ jobs: uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} + flags: tests verbose: true # optional (default = false) - name: Generate and publish the report diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c55c7e93d..d0e244f507 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,6 +71,7 @@ jobs: uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} + flags: tests verbose: true # optional (default = false) test-upstream-and-min-deps: @@ -110,6 +111,7 @@ jobs: uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} + flags: tests verbose: true # optional (default = false) doctests: diff --git a/codecov.yml b/codecov.yml index 745d1f503c..bfeb8e1169 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,10 +6,23 @@ coverage: informational: true project: default: - target: auto - threshold: 0.1 + target: 90% + threshold: 1% + flags: + - tests +flags: + tests: + paths: + - src/ + carryforward: true + gpu: + paths: + - src/ + carryforward: true codecov: notify: + # 6 = test.yml: 3 (optional+ubuntu) + 2 (upstream + min_deps), hypothesis: 1 + after_n_builds: 6 wait_for_ci: yes comment: layout: "diff, files" From 7e47998e0f51c265d3148588f5ee2ae0a0b4c4fa Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:03:56 -0400 Subject: [PATCH 3/5] 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. --- pyproject.toml | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c69a3e4869..ac16436917 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -142,6 +142,7 @@ exclude_also = [ [tool.coverage.run] omit = [ "bench/compress_normal.py", + "src/zarr/_version.py", # auto-generated by setuptools-scm "src/zarr/testing/conftest.py", # only for downstream projects ] @@ -155,10 +156,6 @@ hooks.vcs.version-file = "src/zarr/_version.py" dependency-groups = ["test"] [tool.hatch.envs.test.env-vars] -# Required to test with a pytest plugin; see https://pytest-cov.readthedocs.io/en/latest/plugins.html -COV_CORE_SOURCE = "src" -COV_CORE_CONFIG = "pyproject.toml" -COV_CORE_DATAFILE = ".coverage.eager" [[tool.hatch.envs.test.matrix]] python = ["3.12", "3.13", "3.14"] @@ -175,13 +172,23 @@ matrix.deps.dependency-groups = [ ] [tool.hatch.envs.test.scripts] -run-coverage = "pytest --cov-config=pyproject.toml --cov=src --cov-report xml --junitxml=junit.xml -o junit_family=legacy" -run-coverage-html = "pytest --cov-config=pyproject.toml --cov=src --cov-report html" -run = "run-coverage --no-cov --ignore tests/benchmarks" +run-coverage = [ + "coverage run --source=src -m pytest --junitxml=junit.xml -o junit_family=legacy {args:}", + "coverage xml", +] +run-coverage-html = [ + "coverage run --source=src -m pytest {args:}", + "coverage html", +] +run = "pytest --ignore tests/benchmarks" run-verbose = "run-coverage --verbose" run-mypy = "mypy src" -run-hypothesis = "run-coverage -nauto --run-slow-hypothesis tests/test_properties.py tests/test_store/test_stateful*" +run-hypothesis = [ + "coverage run --source=src -m pytest -nauto --run-slow-hypothesis tests/test_properties.py tests/test_store/test_stateful* {args:}", + "coverage xml", +] run-benchmark = "pytest --benchmark-enable tests/benchmarks" +serve-coverage-html = "python -m http.server -d htmlcov 8000" list-env = "pip list" [tool.hatch.envs.gputest] @@ -195,8 +202,11 @@ features = ["gpu"] python = ["3.12", "3.13"] [tool.hatch.envs.gputest.scripts] -run-coverage = "pytest -m gpu --cov-config=pyproject.toml --cov=src --cov-report xml --junitxml=junit.xml -o junit_family=legacy --ignore tests/benchmarks" -run = "run-coverage --no-cov" +run-coverage = [ + "coverage run --source=src -m pytest -m gpu --junitxml=junit.xml -o junit_family=legacy --ignore tests/benchmarks {args:}", + "coverage xml", +] +run = "pytest -m gpu --ignore tests/benchmarks" [tool.hatch.envs.upstream] template = 'test' From b695fe167f0196fa67760f28f11fcc444444b068 Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:10:26 -0400 Subject: [PATCH 4/5] Revert changes --- codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index bfeb8e1169..a3783cc39a 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,8 +6,8 @@ coverage: informational: true project: default: - target: 90% - threshold: 1% + target: auto + threshold: 0.1 flags: - tests flags: From 50a4db5400c47c8eb1dd407ec78be78484261ed9 Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:11:54 -0400 Subject: [PATCH 5/5] Revert change --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ac16436917..96932a9611 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -142,7 +142,6 @@ exclude_also = [ [tool.coverage.run] omit = [ "bench/compress_normal.py", - "src/zarr/_version.py", # auto-generated by setuptools-scm "src/zarr/testing/conftest.py", # only for downstream projects ]