fix: support GLib event loop policy in scoped runner (#1233) - #1555
Closed
sunilkumarvalmiki wants to merge 1 commit into
Closed
fix: support GLib event loop policy in scoped runner (#1233)#1555sunilkumarvalmiki wants to merge 1 commit into
sunilkumarvalmiki wants to merge 1 commit into
Conversation
Issue pytest-dev#1233: avoid setting a managed loop when GLib's main-context loop is already attached. Preserves non-GLib behavior and avoids the existing baseline test_set_event_loop.py failure. Co-Authored-By: Claude Code <noreply@anthropic.com>
Contributor
|
Thank you for the PR, but I am against solving this issue by treating the GLib event loop policy as privileged within the plugin itself. I would rather solve the issue at its root. Also, please ensure the tox checks are passing before marking a PR as ready for review. |
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.
Description
Fixes #1233:
pytest-asynciofailed with aRuntimeErrorwhenever a test was collected underGLibEventLoopPolicy, because the scoped runner'sasyncio.Runner._lazy_init()callsevents.set_event_loop(loop)and GLib'sset_event_loop()rejects any loop attached on the main thread (it already owns the mainGLib.MainContext).Fix
When the user hasn't supplied an explicit
loop_factory, pass the policy's existing event loop asloop_factorytoasyncio.Runner. The runner then uses the policy's loop and skips the rejectingset_event_loop()call entirely. The policy's loop already lives in the GLib main context, so this is the lifecycle-correct attachment rather than a workaround.GLib detection is done by
policy.__class__.__module__ == "gi.events"— nogiimport is performed, so non-GLib environments see no change.Tests
New
test_event_loop_fixture_supports_glib_policyregression test intests/test_event_loop_fixture.pyruns in a subprocess for isolation.The pre-existing baseline failure in
test_set_event_loop.pyis unrelated and was not touched.Fixes: #1233