From 5e45a4c6c960a0ccf0734967d9f2e60e2edfbfe9 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 17 Aug 2022 12:05:17 +0300 Subject: [PATCH] gh-95736: Fix event loop creation in IsolatedAsyncioTestCase (GH-96033) It should be created before calling the setUp() method, but after checking for skipping a test. Automerge-Triggered-By: GH:tiran (cherry picked from commit 36517101dd80cae93da379e95e98a688c52935b7) Co-authored-by: Serhiy Storchaka --- Lib/unittest/async_case.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py index a90eed98f87140..3457e92e5da298 100644 --- a/Lib/unittest/async_case.py +++ b/Lib/unittest/async_case.py @@ -79,6 +79,10 @@ async def enterAsyncContext(self, cm): return result def _callSetUp(self): + # Force loop to be initialized and set as the current loop + # so that setUp functions can use get_event_loop() and get the + # correct loop instance. + self._asyncioRunner.get_loop() self._asyncioTestContext.run(self.setUp) self._callAsync(self.asyncSetUp)