aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2025-02-07 23:30:59 +0530
committerGitHub <noreply@github.com>2025-02-07 18:00:59 +0000
commit49bd47d5f14993d37b97aa2bbf257f5df16b96a9 (patch)
treec4947fcc180dcadcaf4b5a9b0b95749333d87cf2
parent662e88db642899bcbc28ef142361d5f315a46901 (diff)
downloadcpython-49bd47d5f14993d37b97aa2bbf257f5df16b96a9.tar.gz
cpython-49bd47d5f14993d37b97aa2bbf257f5df16b96a9.zip
improve `test_log_destroyed_pending_task` in asyncio (#129821)
-rw-r--r--Lib/test/test_asyncio/test_tasks.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index cd4a48499e8..881a7aeeb2f 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2254,7 +2254,6 @@ class BaseTaskTests:
asyncio.wait([]))
def test_log_destroyed_pending_task(self):
- Task = self.__class__.Task
async def kill_me(loop):
future = self.new_future(loop)
@@ -2269,7 +2268,7 @@ class BaseTaskTests:
# schedule the task
coro = kill_me(self.loop)
- task = asyncio.ensure_future(coro, loop=self.loop)
+ task = self.new_task(self.loop, coro)
self.assertEqual(self.all_tasks(loop=self.loop), {task})
@@ -2286,14 +2285,17 @@ class BaseTaskTests:
# no more reference to kill_me() task: the task is destroyed by the GC
support.gc_collect()
- self.assertEqual(self.all_tasks(loop=self.loop), set())
-
mock_handler.assert_called_with(self.loop, {
'message': 'Task was destroyed but it is pending!',
'task': mock.ANY,
'source_traceback': source_traceback,
})
mock_handler.reset_mock()
+ # task got resurrected by the exception handler
+ support.gc_collect()
+
+ self.assertEqual(self.all_tasks(loop=self.loop), set())
+
@mock.patch('asyncio.base_events.logger')
def test_tb_logger_not_called_after_cancel(self, m_log):