]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix various warnings in `test_asyncio.test_tasks` (#131109)
authorKumar Aditya <kumaraditya@python.org>
Tue, 11 Mar 2025 19:51:53 +0000 (01:21 +0530)
committerGitHub <noreply@github.com>
Tue, 11 Mar 2025 19:51:53 +0000 (19:51 +0000)
Lib/test/test_asyncio/test_tasks.py

index 591b48b88a268c7810c60a2973e68c7987a23d3f..f1a665e5df3fd3394836bc5fd421f1b6183f3055 100644 (file)
@@ -2301,16 +2301,19 @@ class BaseTaskTests:
             def __del__(self):
                 pass
 
-        async def coro():
+        async def corofn():
             await asyncio.sleep(0.01)
 
-        task = Subclass(coro(), loop = self.loop)
+        coro = corofn()
+        task = Subclass(coro, loop = self.loop)
         task._log_destroy_pending = False
 
         del task
 
         support.gc_collect()
 
+        coro.close()
+
     @mock.patch('asyncio.base_events.logger')
     def test_tb_logger_not_called_after_cancel(self, m_log):
         loop = asyncio.new_event_loop()
@@ -2716,12 +2719,12 @@ class BaseTaskTests:
         coro = coroutine_function()
         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())
 
             coro.close()
+            task._log_destroy_pending = False
             del task
 
             self.assertEqual(sys.getrefcount(obj), initial_refcount)