]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-127949: fix resource warnings in `test_tasks.py` (GH-128172) (#131805)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 28 Mar 2025 14:02:03 +0000 (15:02 +0100)
committerGitHub <noreply@github.com>
Fri, 28 Mar 2025 14:02:03 +0000 (19:32 +0530)
gh-127949: fix resource warnings in `test_tasks.py` (GH-128172)
(cherry picked from commit b66a4ad9fc32b63da2ba10db24cbc8f4e29f781a)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Lib/test/test_asyncio/test_tasks.py

index 313eed9d715158a4f2c56e85c846fa00e01de58e..54692713011278286cebec7fa6666a3f375a3173 100644 (file)
@@ -2694,17 +2694,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):