Uh oh!
There was an error while loading. Please reload this page.
fix(tests): isolate sync test from the module-scoped async fixture - #4
fix(tests): isolate sync test from the module-scoped async fixture#4ClaraVnk wants to merge 1 commit into
Conversation
Test (redis) fails in CI with "RuntimeError: Event loop is closed", raised while the module-scoped `client` fixture closes the Redis connection during teardown. 110 tests pass; only the finalizer errors. CI attributes the finalizer to test_abs_url_prefers_configured_base_url, at 37% of the module — the fixture is finalized mid-module rather than at module exit. That test is the only synchronous one in an otherwise fully async module whose `client` fixture is bound to a module-scoped event loop. It is a pure unit test of _abs_url: it uses neither the client nor the loop, so it moves to its own module with no async fixtures. test_api.py is now uniformly async. Not reproducible locally: with CI-identical package versions (pytest 9.1.1, pytest-asyncio 1.4.0, redis 8.0.1) and redis:7-alpine, the suite is green 5/5 on CPython 3.14.4 and the finalizer observably runs on a live loop. CI runs 3.14.6. The premature finalization is therefore confirmed only from CI output, and CI is the oracle for this fix.
ClaraVnk
commented
Jul 20, 2026
Diagnosis falsified — do not merge as-isCI run on this branch: 29729737295. The teardown error simply moved to the test now occupying that slot: That test is async. The premise of this PR — that a lone synchronous test was triggering premature finalization — is therefore wrong. The module-scoped What the new data suggestsThe That is a hypothesis, not a conclusion. I have not verified it, and I was already wrong once here. StatusLeaving this open for the reorganisation itself, which stands on its own (a pure unit test does not belong in a module-scoped-async-fixture module) but fixes nothing. The underlying failure needs a decision about which async plugin owns this suite — a larger change than this PR. Still unreproducible locally: green 5/5 on CPython 3.14.4 with CI-matched packages and |
ClaraVnk
commented
Jul 20, 2026
Closing: the diagnosis behind this PR was falsified by its own CI run (see the comment above — the teardown error simply moved to the async test occupying that slot). The reorganisation is defensible on its own but fixes nothing, and leaving it open would imply a fix is pending here. The underlying failure needs a decision about which async plugin owns the suite ( Reproducibility groundwork is in #5. |
Contexte
Test (redis)is red onmain, independently of any open PR. Baseline run on untouchedmain: 29729210049 —110 passed, 1 error.The error is a fixture teardown, not a test:
The last green run on
mainwas 2026-05-24. The workflow pinspython-version: "3.14", which resolved to a different patch release then; it resolves to 3.14.6 today. Nobody broke this — the environment moved.Changements
CI attributes the finalizer to
test_abs_url_prefers_configured_base_urlat 37% of the module, meaning the module-scopedclientfixture is finalized mid-module instead of at module exit. That test is the only synchronous one in an otherwise fully async module whoseclientfixture is bound to a module-scoped event loop (see theasyncio_default_fixture_loop_scope = "module"rationale inpyproject.toml, and the earlierfix(tests): module-scope pytest-asyncio loop so Redis fixture survives).It is a pure unit test of
_abs_url— it touches neither the client nor the loop — so it moves totests/test_urls.py, a module with no async fixtures.test_api.pyis now uniformly async.Tests
Local, CPython 3.14.4, package versions matched to CI (pytest 9.1.1, pytest-asyncio 1.4.0, redis 8.0.1) against
redis:7-alpine:ruff check/ruff format --checkcleanRisques
This fix is not locally reproducible, and I want that stated plainly. On 3.14.4 the suite is green 5/5 even before the change, and an instrumented finalizer observably runs on a live loop. CI runs 3.14.6, which I could not obtain (
uvoffers up to 3.14.4). So the premature-finalization diagnosis rests on CI output alone, and CI is the oracle for this change — ifTest (redis)goes green here, the diagnosis holds; if not, the root cause is elsewhere and this should be reworked rather than layered on.Zero production code is touched. Worst case, this is a no-op reorganisation that improves test hygiene.
A more durable follow-up, out of scope here: pin the patch version in the workflow (
python-version: "3.14.6") so the toolchain stops drifting silently between runs.