Skip to content

Fix the combined coverage report - #238

Open
rudaporto wants to merge 8 commits into
masterfrom
fix-tox-config-file-coverage-report
Open

Fix the combined coverage report#238
rudaporto wants to merge 8 commits into
masterfrom
fix-tox-config-file-coverage-report

Conversation

@rudaporto

@rudaporto rudaporto commented Oct 15, 2022

Copy link
Copy Markdown

Reworked on top of current master.

The original 2022 branch could not be rebased: it targeted Python 3.6–3.11,
[coverage:run] sections that have since moved into pyproject.toml,
actions/*@v2, and a pip-based CI that has since moved to uv. The analysis
in the original PR was correct and is what this implements — credit to
@rudaporto.

The bug

combined-coverage depended on the coverage environment and both wrote to
.coverage, so its coverage erase destroyed the data it was meant to
combine — including the Sphinx doctest coverage, which was measured nowhere
else. It also omitted py315 from depends and hard-coded
--fail-under=100 on the command line, contradicting fail_under = 97.1 in
pyproject.toml. On top of that, the coverage environment re-ran the whole
test suite that the per-version environments had just run.

What changed

  • [testenv:coverage] is now the combining environment, and
    [testenv:combined-coverage] is gone. This needed no zope.meta template
    changes
    — the existing coverage-command and coverage-additional
    options already produce exactly the required environment.
  • py315 added to depends. Note that depends orders environments in
    sequential runs too, not only under tox -p, so coverage runs last
    regardless of its position in the envlist.
  • The per-version environments no longer gate on coverage
    (--cov-fail-under=0): a single Python version cannot reach 100 %, only the
    combination can. The threshold is enforced once, on the combined report.
  • fail_under raised to 100 and actually met:
    • added the missing test for an ast.Expression body in
      compile_restricted_function (compile.py lines 179–181 were untested),
    • excluded the typing.overload stubs in Limits.py and the
      typing.Protocol stub in Eval.py, whose bodies never execute at runtime
      by design.
  • relative_files = true so the data stays portable across machines.

Result

Combined coverage is 100.00 % over py310–py315 plus py311-datetime.
A single version reaches only 99.76 %, which is the whole point: the
version-conditional code (_types.py, the t-string and except* tests) can
only be covered by the union.

Verified locally: tox -e lint,docs,py310,py311,py312,py313,py314,py315,py311-datetime,coverage
and release-check all pass, sequentially and under tox -p auto. Combining
from a single version's data correctly fails the gate at 99.76 %.

Scope

CI still measures a single Python version. Moving CI onto the combined report
requires new zope.meta template support (there is no hook to add a step after
Test, nor to add a job), so it follows separately — see the issue filed
against zopefoundation/meta.

Comment created by Claude

@rudaporto
rudaporto requested review from ale-rt and loechel October 15, 2022 13:46
@rudaporto
rudaporto force-pushed the fix-tox-config-file-coverage-report branch 2 times, most recently from e352897 to 579c0b1 Compare October 15, 2022 15:15
@rudaporto
rudaporto force-pushed the fix-tox-config-file-coverage-report branch from 579c0b1 to 95272c2 Compare October 15, 2022 15:33
@rudaporto

Copy link
Copy Markdown
Author

When using the matrix execution we can not collect the combined coverage from each python version.

@rudaporto rudaporto closed this Oct 15, 2022
@davisagli

Copy link
Copy Markdown
Member

https://hynek.me/articles/ditch-codecov-python/ has a suggestion of how to do this

@rudaporto rudaporto reopened this Oct 16, 2022
@rudaporto
rudaporto force-pushed the fix-tox-config-file-coverage-report branch 3 times, most recently from 3eeac16 to 9730e11 Compare October 16, 2022 08:52
@dataflake

Copy link
Copy Markdown
Member

FYI, the file .github/workflows/tests.yml is auto-generated and should not be edited by hand. It uses the meta/config package, see https://github.com/zopefoundation/meta/tree/master/config, which is configured using the .meta.toml file.

@rudaporto
rudaporto force-pushed the fix-tox-config-file-coverage-report branch 10 times, most recently from 619000e to 338da05 Compare October 16, 2022 10:56
Build job:
- add upload artifact step after each test in the matrix.
- update coveralls step to upload partial data.

Converage job (new):
- complete the coveralls in the coverage job.
- add step to download all uploaded artifacts
- add step to combine coverage data, create report and fail if not
  enough
- add step to upload html report if coverage is not enough
@rudaporto
rudaporto force-pushed the fix-tox-config-file-coverage-report branch from 338da05 to f3704f2 Compare October 17, 2022 07:05
@rudaporto

rudaporto commented Oct 17, 2022

Copy link
Copy Markdown
Author

FYI, the file .github/workflows/tests.yml is auto-generated and should not be edited by hand. It uses the meta/config package, see https://github.com/zopefoundation/meta/tree/master/config, which is configured using the .meta.toml file.

Thank you @dataflake for the reminder. Yes, I know that this should not be changed directly.
I've updated the description with a full explanation of what I tried to achieve.

I will convert this PR to a draft to avoid confusion.

@rudaporto
rudaporto marked this pull request as draft October 17, 2022 07:12
@icemac

icemac commented Oct 26, 2022

Copy link
Copy Markdown
Member

I think this approach presented here is promising. It requires some changes in meta/config so it can produce the required tests.yaml.
Currently we are running coverage just for one Python version. In most projects this is enough because (after dropping Python 2 support) there is nearly no Python version specific code. So for the other projects I think it will be enough just to run coverage on a single Python version, but here we have different goals.

I currently do not have the time and energy to push meta/config forward to be able to support the kind of changes required here, sorry.

@icemac icemac mentioned this pull request Oct 27, 2022
@icemac
icemac removed their request for review April 3, 2025 07:26
icemac added 2 commits August 7, 2026 09:04
The `coverage` tox environment now combines the coverage data of all
supported Python versions instead of measuring a single one, and enforces
100% coverage.

Previously the `combined-coverage` environment was supposed to do this, but
it depended on the `coverage` environment and both wrote to `.coverage`, so
its `coverage erase` threw away the data it was meant to combine -- including
the Sphinx doctest coverage, which was measured nowhere else. It also omitted
`py315` from `depends` and hard-coded `--fail-under=100` on the command line,
contradicting the `fail_under` in `pyproject.toml`.

Changes:

- Turn `[testenv:coverage]` into the combining environment via the existing
  `coverage-command` / `coverage-additional` zope.meta options, and drop
  `[testenv:combined-coverage]`. No template changes were needed.
- Add `py315` to `depends`. `depends` orders environments in sequential runs
  too, not just under `tox -p`, so `coverage` runs last regardless of its
  position in the envlist.
- Disable the coverage threshold for the per-version environments: a single
  Python version cannot reach 100%, only the combination can.
- Set `fail_under` to 100 and reach it:
  - add the missing test for an `ast.Expression` body in
    `compile_restricted_function` (`compile.py` lines 179-181),
  - exclude the `typing.overload` stubs in `Limits.py` and the
    `typing.Protocol` stub in `Eval.py`, whose bodies never execute at
    runtime by design.
- Add `relative_files = true` so the data stays portable across machines.

Combined coverage is now 100.00% over py310-py315 plus py311-datetime; a
single version reaches only 99.76%.

CI still measures a single Python version -- moving it to the combined report
needs new zope.meta template support and follows separately.

Based on the analysis in PR #238 by Rudá Porto Filgueiras.
@icemac icemac changed the title fix: combined coverage report Fix the combined coverage report Aug 7, 2026
@icemac
icemac marked this pull request as ready for review August 7, 2026 07:59
@icemac icemac self-assigned this Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants