]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127949: fix resource warnings in `test_tasks.py` (#128172)
authorThomas Grainger <tagrain@gmail.com>
Sun, 22 Dec 2024 12:46:02 +0000 (12:46 +0000)
committerGitHub <noreply@github.com>
Sun, 22 Dec 2024 12:46:02 +0000 (18:16 +0530)
Lib/test/test_asyncio/test_tasks.py

index 5b8979a8bbd13ac0a9695fc4f725069c92332cd5..7d6d0564a9a9db0d2f73adbe79aceff203655053 100644 (file)
@@ -2698,17 +2698,17 @@ class BaseTaskTests:
         initial_refcount = sys.getrefcount(obj)
 
         coro = coroutine_function()
-        loop = asyncio.new_event_loop()
-        task = asyncio.Task.__new__(asyncio.Task)
+        with contextlib.closing(asyncio.EventLoop()) as loop:
+            task = asyncio.Task.__new__(asyncio.Task)
 
-        for _ in range(5):
-            with self.assertRaisesRegex(RuntimeError, 'break'):
-                task.__init__(coro, loop=loop, context=obj, name=Break())
+            for _ in range(5):
+                with self.assertRaisesRegex(RuntimeError, 'break'):
+                    task.__init__(coro, loop=loop, context=obj, name=Break())
 
-        coro.close()
-        del task
+            coro.close()
+            del task
 
-        self.assertEqual(sys.getrefcount(obj), initial_refcount)
+            self.assertEqual(sys.getrefcount(obj), initial_refcount)
 
 
 def add_subclass_tests(cls):