Skip to content

Commit 216cc99

Browse files
Add a comment about clearing the policy.
1 parent b0519f9 commit 216cc99

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Lib/test/test_concurrent_futures/test_interpreter_pool.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,16 @@ class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):
284284

285285
@classmethod
286286
def setUpClass(cls):
287+
# Most uses of asyncio will implicitly call set_event_loop_policy()
288+
# with the default policy if a policy hasn't been set already.
289+
# If that happens in a test, likw here, we'll end up with a failure
290+
# when --fail-env-changed is used. That's why the other tests that
291+
# use asyncio are careful to set the policy back to None and why
292+
# we're careful to do so here. We also validate that no other
293+
# tests left a policy in place, just in case.
287294
policy = support.maybe_get_event_loop_policy()
288295
assert policy is None, policy
289-
290-
@classmethod
291-
def tearDownClass(cls):
292-
asyncio.set_event_loop_policy(None)
296+
cls.addClassCleanup(lambda: asyncio.set_event_loop_policy(None))
293297

294298
def setUp(self):
295299
super().setUp()

0 commit comments

Comments
 (0)