Fix event_loop_policy parametrization scope#1454
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1454 +/- ##
==========================================
+ Coverage 94.50% 94.75% +0.24%
==========================================
Files 2 2
Lines 510 534 +24
Branches 62 69 +7
==========================================
+ Hits 482 506 +24
Misses 22 22
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
golikovichev
left a comment
There was a problem hiding this comment.
Approach looks clean. Dropping autouse=True from the event_loop_policy fixture and gating its injection on pytest_generate_tests only when the test uses asyncio fixtures (or is async itself) is the right shape to fix #796 without breaking the loop-policy parametrization use case.
Two observations from a downstream-user read:
_uses_asyncio_fixtureswalksmetafunc._arg2fixturedefsand short-circuits on first match. In AUTO mode it falls back to_is_coroutine_or_asyncgen, which is what catches sync tests that happen to request async fixtures - exactly the gap #796 surfaced. Worth keeping the AUTO branch as-is even though it adds a per-fixture check.- The negative-case regression test
test_parametrized_loop_policy_does_not_parametrize_sync_testsis paired withtest_parametrized_loop_policy_parametrizes_sync_tests_with_async_fixtures(positive case). Good coverage pattern.
CI green across the full matrix (Py 3.10-3.14 + Windows + pytest main). Lint + mypy + pyright also clean per PR body.
Not a maintainer, leaving this as a non-blocking review.
golikovichev
left a comment
There was a problem hiding this comment.
Good catch with the MRE. My read was too superficial - I focused on the autouse change and the regression test pair, but missed that _add_fixture_to_metafunc injecting event_loop_policy breaks valid fixture chains where event_loop_policy depends on another parametrized fixture (like your policy). The patch shifts the parametrization origin out from under pytest's resolver.
Leaving this to the PR author and maintainers.
golikovichev
left a comment
There was a problem hiding this comment.
Re-reviewed after 8305b3a. The new _add_fixture_to_metafunc walks the closure via fixturemanager.getfixtureclosure() instead of attaching just the named fixture, so parametrize chains like event_loop_policy(policy) from @tjkuson's MRE are now preserved end to end.
The new test test_parametrized_loop_policy_can_depend_on_parametrized_fixture mirrors the MRE shape directly (parametrized policy fixture, event_loop_policy(policy) depending on it, both async and sync tests), so the regression is pinned. The two surrounding sync-vs-async parametrization tests cover the adjacent cases I would have asked for, so I do not have anything to add.
Sorry again for missing this in my first read - your MRE made the failure mode obvious, and the fix landed cleanly.
gmail-precheck-done
|
Pushed cd89044 to cover the remaining event loop policy fixture discovery paths from the Codecov report. Added coverage for auto-mode regular async fixtures and strict-mode unmarked async tests that still need the policy fixture closure. Verified locally:
|
Summary
Fixes #796
Tests