GH-93896: AAlways set event loop in asyncio.run and IsolatedAsyncioTe… · python/cpython@14fea6b · GitHub
Skip to content

Commit 14fea6b

Browse files
GH-93896: AAlways set event loop in asyncio.run and IsolatedAsyncioTestCase (#94593)
1 parent e925241 commit 14fea6b

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

Lib/asyncio/runners.py

Lines changed: 6 additions & 0 deletions

Lib/test/test_asyncio/test_runners.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ async def main():
198198
self.assertIsNone(spinner.ag_frame)
199199
self.assertFalse(spinner.ag_running)
200200

201+
def test_asyncio_run_set_event_loop(self):
202+
#See https://github.com/python/cpython/issues/93896
203+
204+
async def main():
205+
await asyncio.sleep(0)
206+
return 42
207+
208+
policy = asyncio.get_event_loop_policy()
209+
policy.set_event_loop = mock.Mock()
210+
asyncio.run(main())
211+
self.assertTrue(policy.set_event_loop.called)
212+
201213

202214
class RunnerTests(BaseTest):
203215

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)