async def _coro_cancel_itself_after_sleep(future): await _sleep(0.0001) aio.current_task().cancel() await future
async def _coro_cancel_itself(future): aio.current_task().cancel() await future
async def _coro_return_current_task(): return aio.current_task()
def test_current_task_on_explicit_non_running_loop(loop): assert aio.current_task(loop) is None
def test_current_task_on_not_running_loop(): with pytest.raises(RuntimeError): aio.current_task()
def test_current_task_in_call_soon(loop): tasks = [] loop.call_soon(lambda: tasks.append(aio.current_task())) loop.call_soon(_Stopper(loop)) loop.run_forever() assert tasks == [None]