https://github.com/python/cpython/commit/d73d69e232ce848733517736b1761e7bd2478574
commit: d73d69e232ce848733517736b1761e7bd2478574
branch: main
author: Kumar Aditya <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-02-24T21:33:52+05:30
summary:
gh-129874: improve tests to use correct implementations in asyncio (#130516)
files:
M Lib/test/test_asyncio/test_eager_task_factory.py
M Lib/test/test_asyncio/test_free_threading.py
diff --git a/Lib/test/test_asyncio/test_eager_task_factory.py
b/Lib/test/test_asyncio/test_eager_task_factory.py
index bb0760a6967dba..a2fb1022ae4d3f 100644
--- a/Lib/test/test_asyncio/test_eager_task_factory.py
+++ b/Lib/test/test_asyncio/test_eager_task_factory.py
@@ -268,12 +268,15 @@ class
PyEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase
Task = tasks._PyTask
def setUp(self):
+ self._all_tasks = asyncio.all_tasks
self._current_task = asyncio.current_task
asyncio.current_task = asyncio.tasks.current_task =
asyncio.tasks._py_current_task
+ asyncio.all_tasks = asyncio.tasks.all_tasks =
asyncio.tasks._py_all_tasks
return super().setUp()
def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task = self._current_task
+ asyncio.all_tasks = asyncio.tasks.all_tasks = self._all_tasks
return super().tearDown()
@@ -285,11 +288,14 @@ class
CEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase)
def setUp(self):
self._current_task = asyncio.current_task
+ self._all_tasks = asyncio.all_tasks
asyncio.current_task = asyncio.tasks.current_task =
asyncio.tasks._c_current_task
+ asyncio.all_tasks = asyncio.tasks.all_tasks =
asyncio.tasks._c_all_tasks
return super().setUp()
def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task = self._current_task
+ asyncio.all_tasks = asyncio.tasks.all_tasks = self._all_tasks
return super().tearDown()
diff --git a/Lib/test/test_asyncio/test_free_threading.py
b/Lib/test/test_asyncio/test_free_threading.py
index 199dbbdda5e8a6..110996c348554c 100644
--- a/Lib/test/test_asyncio/test_free_threading.py
+++ b/Lib/test/test_asyncio/test_free_threading.py
@@ -33,7 +33,7 @@ async def coro():
for _ in range(100):
tasks.add(tg.create_task(coro()))
- all_tasks = self.all_tasks(loop)
+ all_tasks = asyncio.all_tasks(loop)
self.assertEqual(len(all_tasks), 101)
for task in all_tasks:
@@ -77,7 +77,7 @@ async def main():
for i in range(1000):
with lock:
asyncio.create_task(coro())
- tasks = self.all_tasks(loop)
+ tasks = asyncio.all_tasks(loop)
done.wait()
runner = threading.Thread(target=lambda: asyncio.run(main()))
@@ -85,7 +85,7 @@ async def main():
def check():
started.wait()
with lock:
- self.assertSetEqual(tasks & self.all_tasks(loop), tasks)
+ self.assertSetEqual(tasks & asyncio.all_tasks(loop), tasks)
threads = [threading.Thread(target=check) for _ in range(10)]
runner.start()
@@ -167,15 +167,23 @@ async def main():
class TestPyFreeThreading(TestFreeThreading, TestCase):
- all_tasks = staticmethod(asyncio.tasks._py_all_tasks)
def setUp(self):
self._old_current_task = asyncio.current_task
asyncio.current_task = asyncio.tasks.current_task =
asyncio.tasks._py_current_task
+ self._old_all_tasks = asyncio.all_tasks
+ asyncio.all_tasks = asyncio.tasks.all_tasks =
asyncio.tasks._py_all_tasks
+ self._old_Task = asyncio.Task
+ asyncio.Task = asyncio.tasks.Task = asyncio.tasks._PyTask
+ self._old_Future = asyncio.Future
+ asyncio.Future = asyncio.futures.Future = asyncio.futures._PyFuture
return super().setUp()
def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task =
self._old_current_task
+ asyncio.all_tasks = asyncio.tasks.all_tasks = self._old_all_tasks
+ asyncio.Task = asyncio.tasks.Task = self._old_Task
+ asyncio.Future = asyncio.tasks.Future = self._old_Future
return super().tearDown()
def factory(self, loop, coro, **kwargs):
@@ -184,15 +192,23 @@ def factory(self, loop, coro, **kwargs):
@unittest.skipUnless(hasattr(asyncio.tasks, "_c_all_tasks"), "requires
_asyncio")
class TestCFreeThreading(TestFreeThreading, TestCase):
- all_tasks = staticmethod(getattr(asyncio.tasks, "_c_all_tasks", None))
def setUp(self):
self._old_current_task = asyncio.current_task
asyncio.current_task = asyncio.tasks.current_task =
asyncio.tasks._c_current_task
+ self._old_all_tasks = asyncio.all_tasks
+ asyncio.all_tasks = asyncio.tasks.all_tasks =
asyncio.tasks._c_all_tasks
+ self._old_Task = asyncio.Task
+ asyncio.Task = asyncio.tasks.Task = asyncio.tasks._CTask
+ self._old_Future = asyncio.Future
+ asyncio.Future = asyncio.futures.Future = asyncio.futures._CFuture
return super().setUp()
def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task =
self._old_current_task
+ asyncio.all_tasks = asyncio.tasks.all_tasks = self._old_all_tasks
+ asyncio.Task = asyncio.tasks.Task = self._old_Task
+ asyncio.Future = asyncio.futures.Future = self._old_Future
return super().tearDown()
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]