]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
improve `test_tasks` to use correct idiom for starting task in asyncio (#130257)
authorKumar Aditya <kumaraditya@python.org>
Tue, 18 Feb 2025 12:08:25 +0000 (17:38 +0530)
committerGitHub <noreply@github.com>
Tue, 18 Feb 2025 12:08:25 +0000 (12:08 +0000)
The test should use the correct idiom for starting the task, `loop._run_once` is private API which should not be used directly, instead use `asyncio.sleep(0)` for 1 event loop cycle.

Lib/test/test_asyncio/test_tasks.py

index de2e658bca66a02c5806261bde4ed26b24fbbf4a..591b48b88a268c7810c60a2973e68c7987a23d3f 100644 (file)
@@ -2272,10 +2272,8 @@ class BaseTaskTests:
 
         self.assertEqual(self.all_tasks(loop=self.loop), {task})
 
-        asyncio._set_event_loop(None)
-
         # execute the task so it waits for future
-        self.loop._run_once()
+        self.loop.run_until_complete(asyncio.sleep(0))
         self.assertEqual(len(self.loop._ready), 0)
 
         coro = None