Repository navigation
Allow event loop policies that reject set_event_loop (#1233) - #1625
Open
krishashah-03 wants to merge 2 commits into
Open
krishashah-03 wants to merge 2 commits into
krishashah-03 wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1625 +/- ##
==========================================
- Coverage 94.86% 94.32% -0.54%
==========================================
Files 2 2
Lines 506 511 +5
Branches 60 59 -1
==========================================
+ Hits 480 482 +2
- Misses 21 23 +2
- Partials 5 6 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Related to #1233.
What
_scoped_runnerno longer fails when the active event loop policy refusesasyncio.set_event_loop().Why
When no
loop_factoryis configured,asyncio.Runnercallsasyncio.set_event_loop()on setup. Policies that manage the main-thread loopthemselves, such as
GLibEventLoopPolicy, raiseRuntimeError: Thread already has a main context, so every async test errorsat fixture setup.
Change
asyncio.new_event_loopwhen theuser has not configured one), so the runner doesn't call
set_event_loop()._set_event_loop()ourselves and tolerate aRuntimeError. The loop stillruns the test, and
asyncio.get_running_loop()works inside coroutines.asyncio.new_event_loopis used instead ofget_event_loop_policy(), which isdeprecated in 3.14 and removed in 3.16.
Testing
test_runner_works_with_policy_that_rejects_setting_loopintests/test_set_event_loop.py. It fails onmainwith the error above andpasses with this change.
python -m pytest tests/test_set_event_loop.py: all pass excepttest_asyncio_run_after_async_fixture_does_not_leak_loop, which fails the sameway on unmodified
mainin my environment (pytest 9.2.0,PytestAssertRewriteWarning).