]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95736: Fix event loop creation in IsolatedAsyncioTestCase (GH-96033)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 17 Aug 2022 09:05:17 +0000 (12:05 +0300)
committerGitHub <noreply@github.com>
Wed, 17 Aug 2022 09:05:17 +0000 (02:05 -0700)
It should be created before calling the setUp() method, but after
checking for skipping a test.

Automerge-Triggered-By: GH:tiran
Lib/unittest/async_case.py

index 8b06fad062094602b0fdddedecbded9732a5db9d..3457e92e5da298fa0995daee8ff9871aa968e13f 100644 (file)
@@ -79,6 +79,10 @@ class IsolatedAsyncioTestCase(TestCase):
         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)
 
@@ -116,10 +120,6 @@ class IsolatedAsyncioTestCase(TestCase):
         assert self._asyncioRunner is None, 'asyncio runner is already initialized'
         runner = asyncio.Runner(debug=True)
         self._asyncioRunner = runner
-        # 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.
-        runner.get_loop()
 
     def _tearDownAsyncioRunner(self):
         runner = self._asyncioRunner