Drop -n 4 xdist parallelism from the pytest-coverage pre-commit hook

The coverage gate failed twice in a row on GitHub Actions on the exact
same line (wake_alarm/_alarm_display.py:71), with the run rerun on the
identical commit -- ruling out a one-off flake. Could not reproduce
locally across 6 attempts, including running the exact same -n 4
invocation directly. The likely cause is a pytest-xdist/pytest-cov
worker coverage-combine timing issue specific to the CI runner that
isn't practical to root-cause further from here. Running the hook
serially removes the risk outright; local timing shows no meaningful
slowdown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A7vbgtFfZmfxJtN5DdtJky
This commit is contained in:
Krzysztof kuhy Rudnicki 2026-06-22 08:29:54 +02:00
parent f34c4cc670
commit d8f8605275
2 changed files with 34 additions and 2 deletions

View File

@ -0,0 +1,28 @@
{
"intent": "Eliminate a reproducible (not flaky) coverage-gate false failure on GitHub Actions, where pytest-xdist's -n 4 workers combined with pytest-cov consistently dropped coverage of one specific line (wake_alarm/_alarm_display.py:71) on the CI runner, never locally.",
"scope": [
"meta/scripts/pytest_changed_packages.py (the pre-commit pytest-coverage hook entry point)",
"Non-goal: a full root-cause diagnosis of the xdist/coverage interaction itself -- not reproducible locally despite 6 attempts, so the fix removes the risk rather than chasing the exact mechanism"
],
"changes": [
"Removed the -n 4 (pytest-xdist parallel workers) flag from the pytest invocation this hook runs. Serial execution has never produced a coverage gap in any local or CI run; -n 4 produced the identical gap on two consecutive CI runs (a rerun of the same commit), which rules out a one-off flake and points at a CI-runner-specific worker/coverage-combine timing issue this repo cannot fix at the pytest-cov/xdist level from here."
],
"verification": [
{
"command": "time python meta/scripts/pytest_changed_packages.py python_pkg/wake_alarm/_alarm.py",
"result": "pass",
"evidence": "948 passed, 100.00% coverage, 14.3s total -- functionally identical runtime to the parallel version locally, with the coverage gap gone"
},
{
"command": "pre-commit run --all-files",
"result": "pass",
"evidence": "all hooks green including pytest-coverage"
}
],
"risks": [
"Slightly slower CI runs without parallelism, though local timing showed negligible difference (~13-14s either way for this test count); reliability of the 100%-coverage gate matters more than a few seconds"
],
"rollback": [
"git revert this commit to restore -n 4 if CI proves the gap was actually something else (e.g. transient runner load) -- but two identical consecutive failures on the same line make that unlikely"
]
}

View File

@ -56,8 +56,12 @@ def main() -> int:
"--cov-report=term-missing",
"--cov-fail-under=100",
"-q",
"-n",
"4",
# No -n/xdist: pytest-cov's worker coverage combine has shown a
# reproducible (not flaky -- failed identically twice in a row) gap
# under -n 4 on the GitHub Actions runner that never occurs running
# serially, including run repeatedly with the same -n 4 locally.
# Serial is slightly slower but has never produced a false coverage
# failure, which matters more for a 100%-coverage gate.
# Override addopts from pyproject.toml to avoid double --cov flags.
"-o",
"addopts=--strict-markers --strict-config -ra",