55import asyncio
66from collections .abc import AsyncIterator , Awaitable , Coroutine , Iterator
77from copy import copy , deepcopy
8- from random import randint
98from typing import NoReturn
109from unittest import mock
1110
@@ -66,7 +65,6 @@ def mock_logger(mocker: MockerFixture) -> Iterator[mock.Mock]:
6665
6766
6867async def test_logged_gather (
69- event_loop : asyncio .AbstractEventLoop ,
7068 coros : list [Coroutine ],
7169 mock_logger : mock .Mock ,
7270):
@@ -79,7 +77,7 @@ async def test_logged_gather(
7977 # NOTE: only first error in the list is raised, since it is not RuntimeError, that task
8078 assert isinstance (excinfo .value , ValueError )
8179
82- for task in asyncio .all_tasks (event_loop ):
80+ for task in asyncio .all_tasks (asyncio . get_running_loop () ):
8381 if task is not asyncio .current_task ():
8482 # info
8583 task .print_stack ()
@@ -148,7 +146,7 @@ async def test_fire_and_forget_1000s_tasks(faker: Faker):
148146 tasks_collection = set ()
149147
150148 async def _some_task (n : int ) -> str :
151- await asyncio .sleep (randint (1 , 3 ))
149+ await asyncio .sleep (faker . random_int (1 , 3 ))
152150 return f"I'm great since I slept a bit, and by the way I'm task { n } "
153151
154152 for n in range (1000 ):
@@ -251,7 +249,6 @@ async def test_limited_gather_limits(
251249
252250
253251async def test_limited_gather (
254- event_loop : asyncio .AbstractEventLoop ,
255252 coros : list [Coroutine ],
256253 mock_logger : mock .Mock ,
257254):
@@ -266,7 +263,7 @@ async def test_limited_gather(
266263
267264 unfinished_tasks = [
268265 task
269- for task in asyncio .all_tasks (event_loop )
266+ for task in asyncio .all_tasks (asyncio . get_running_loop () )
270267 if task is not asyncio .current_task ()
271268 ]
272269 final_results = await asyncio .gather (* unfinished_tasks , return_exceptions = True )
@@ -288,9 +285,7 @@ async def test_limited_gather_wo_raising(
288285 assert results [5 ] == 5
289286
290287
291- async def test_limited_gather_cancellation (
292- event_loop : asyncio .AbstractEventLoop , slow_successful_coros_list : list [Coroutine ]
293- ):
288+ async def test_limited_gather_cancellation (slow_successful_coros_list : list [Coroutine ]):
294289 task = asyncio .create_task (limited_gather (* slow_successful_coros_list , limit = 0 ))
295290 await asyncio .sleep (3 )
296291 task .cancel ()
@@ -300,7 +295,7 @@ async def test_limited_gather_cancellation(
300295 # check all coros are cancelled
301296 unfinished_tasks = [
302297 task
303- for task in asyncio .all_tasks (event_loop )
298+ for task in asyncio .all_tasks (asyncio . get_running_loop () )
304299 if task is not asyncio .current_task ()
305300 ]
306301 assert not unfinished_tasks
0 commit comments