]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-124694: In test_interpreter_pool, Restore the Asyncio Event Loop Policy During...
authorEric Snow <ericsnowcurrently@gmail.com>
Fri, 18 Oct 2024 22:05:12 +0000 (16:05 -0600)
committerGitHub <noreply@github.com>
Fri, 18 Oct 2024 22:05:12 +0000 (16:05 -0600)
This resolves a failure on the android buildbot.

Lib/test/test_concurrent_futures/test_interpreter_pool.py

index 0de03c0d6693999008f4eecc13c9f681a23620cf..5264b1bb6e9c75e9a7e204e758f677f68db13283 100644 (file)
@@ -282,6 +282,19 @@ class InterpreterPoolExecutorTest(
 
 class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):
 
+    @classmethod
+    def setUpClass(cls):
+        # Most uses of asyncio will implicitly call set_event_loop_policy()
+        # with the default policy if a policy hasn't been set already.
+        # If that happens in a test, like here, we'll end up with a failure
+        # when --fail-env-changed is used.  That's why the other tests that
+        # use asyncio are careful to set the policy back to None and why
+        # we're careful to do so here.  We also validate that no other
+        # tests left a policy in place, just in case.
+        policy = support.maybe_get_event_loop_policy()
+        assert policy is None, policy
+        cls.addClassCleanup(lambda: asyncio.set_event_loop_policy(None))
+
     def setUp(self):
         super().setUp()
         self.loop = asyncio.new_event_loop()