@@ -33,7 +33,7 @@ async def coro():
3333 for _ in range (100 ):
3434 tasks .add (tg .create_task (coro ()))
3535
36- all_tasks = self .all_tasks (loop )
36+ all_tasks = asyncio .all_tasks (loop )
3737 self .assertEqual (len (all_tasks ), 101 )
3838
3939 for task in all_tasks :
@@ -77,15 +77,15 @@ async def main():
7777 for i in range (1000 ):
7878 with lock :
7979 asyncio .create_task (coro ())
80- tasks = self .all_tasks (loop )
80+ tasks = asyncio .all_tasks (loop )
8181 done .wait ()
8282
8383 runner = threading .Thread (target = lambda : asyncio .run (main ()))
8484
8585 def check ():
8686 started .wait ()
8787 with lock :
88- self .assertSetEqual (tasks & self .all_tasks (loop ), tasks )
88+ self .assertSetEqual (tasks & asyncio .all_tasks (loop ), tasks )
8989
9090 threads = [threading .Thread (target = check ) for _ in range (10 )]
9191 runner .start ()
@@ -167,15 +167,23 @@ async def main():
167167
168168
169169class TestPyFreeThreading (TestFreeThreading , TestCase ):
170- all_tasks = staticmethod (asyncio .tasks ._py_all_tasks )
171170
172171 def setUp (self ):
173172 self ._old_current_task = asyncio .current_task
174173 asyncio .current_task = asyncio .tasks .current_task = asyncio .tasks ._py_current_task
174+ self ._old_all_tasks = asyncio .all_tasks
175+ asyncio .all_tasks = asyncio .tasks .all_tasks = asyncio .tasks ._py_all_tasks
176+ self ._old_Task = asyncio .Task
177+ asyncio .Task = asyncio .tasks .Task = asyncio .tasks ._PyTask
178+ self ._old_Future = asyncio .Future
179+ asyncio .Future = asyncio .futures .Future = asyncio .futures ._PyFuture
175180 return super ().setUp ()
176181
177182 def tearDown (self ):
178183 asyncio .current_task = asyncio .tasks .current_task = self ._old_current_task
184+ asyncio .all_tasks = asyncio .tasks .all_tasks = self ._old_all_tasks
185+ asyncio .Task = asyncio .tasks .Task = self ._old_Task
186+ asyncio .Future = asyncio .tasks .Future = self ._old_Future
179187 return super ().tearDown ()
180188
181189 def factory (self , loop , coro , ** kwargs ):
@@ -184,15 +192,23 @@ def factory(self, loop, coro, **kwargs):
184192
185193@unittest .skipUnless (hasattr (asyncio .tasks , "_c_all_tasks" ), "requires _asyncio" )
186194class TestCFreeThreading (TestFreeThreading , TestCase ):
187- all_tasks = staticmethod (getattr (asyncio .tasks , "_c_all_tasks" , None ))
188195
189196 def setUp (self ):
190197 self ._old_current_task = asyncio .current_task
191198 asyncio .current_task = asyncio .tasks .current_task = asyncio .tasks ._c_current_task
199+ self ._old_all_tasks = asyncio .all_tasks
200+ asyncio .all_tasks = asyncio .tasks .all_tasks = asyncio .tasks ._c_all_tasks
201+ self ._old_Task = asyncio .Task
202+ asyncio .Task = asyncio .tasks .Task = asyncio .tasks ._CTask
203+ self ._old_Future = asyncio .Future
204+ asyncio .Future = asyncio .futures .Future = asyncio .futures ._CFuture
192205 return super ().setUp ()
193206
194207 def tearDown (self ):
195208 asyncio .current_task = asyncio .tasks .current_task = self ._old_current_task
209+ asyncio .all_tasks = asyncio .tasks .all_tasks = self ._old_all_tasks
210+ asyncio .Task = asyncio .tasks .Task = self ._old_Task
211+ asyncio .Future = asyncio .futures .Future = self ._old_Future
196212 return super ().tearDown ()
197213
198214
0 commit comments