Skip to content

Commit 3651710

Browse files
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
1 parent da0aa51 commit 3651710

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Lib/unittest/async_case.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ async def enterAsyncContext(self, cm):
7979
return result
8080

8181
def _callSetUp(self):
82+
# Force loop to be initialized and set as the current loop
83+
# so that setUp functions can use get_event_loop() and get the
84+
# correct loop instance.
85+
self._asyncioRunner.get_loop()
8286
self._asyncioTestContext.run(self.setUp)
8387
self._callAsync(self.asyncSetUp)
8488

@@ -116,10 +120,6 @@ def _setupAsyncioRunner(self):
116120
assert self._asyncioRunner is None, 'asyncio runner is already initialized'
117121
runner = asyncio.Runner(debug=True)
118122
self._asyncioRunner = runner
119-
# Force loop to be initialized and set as the current loop
120-
# so that setUp functions can use get_event_loop() and get the
121-
# correct loop instance.
122-
runner.get_loop()
123123

124124
def _tearDownAsyncioRunner(self):
125125
runner = self._asyncioRunner

0 commit comments

Comments
 (0)