fix: route around coveragepy#2124 flake in aio finalizer test - #3
Merged
Conversation
CI's pytest(3.11) job intermittently failed the 100%-coverage gate on the same two lines, reproduced live on GitHub Actions (~1-in-4 runs). Traced to an upstream coverage.py bug on Python 3.11 that loses trace lines right after awaiting a coroutine that cancels a task internally, which is exactly what grpc.aio's Server.stop() does. Adds a throwaway scheduling checkpoint so the tracer's blind spot lands there instead of the assertions under test.
The asyncio.sleep(0) checkpoint from the previous commit didn't work: it just relocated the tracer's blind spot onto the checkpoint line itself (confirmed by reproducing the flake again on CI), since the blind spot's width varies rather than being fixed at one line. Switch to marking the affected lines with pragma: no cover, which coverage.py resolves via static parsing rather than runtime tracing, so it's unaffected by the race.
13 consecutive clean pytest(3.11) runs on PR #3 after the pragma-exclusion fix, versus the original ~1-in-4 failure rate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pytest (3.11)job intermittently failed the 100%-coverage gate (~1-in-4 runs, reproduced live on GitHub Actions), always on the same two lines oftest_aio_app_finalizer_runs_on_root_close, despite all tests passing.CancelledError.grpc.aio'sServer.stop()does exactly that to its own background tasks.await asyncio.sleep(0)checkpoint right afterserver.stop(0)so the tracer's blind spot lands there instead of on the assertions under test.planning/changes/2026-07-13.01-aio-coverage-flake.mdandplanning/decisions/2026-07-13-coveragepy-2124-flake.mdfor full investigation and rejected alternatives.Test plan
just test-ci— 100% coverage, 27 passed, locallyjust lint-ci— clean