Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def should_fail(timeout, loop):
task = current_task(loop)
handle = loop.call_later(timeout, task.cancel)
try:
yield
except asyncio.CancelledError:
handle.cancel()
return
else:
msg = 'Inner task expected to be cancelled: {}'.format(task)
pytest.fail(msg)
async def task():
tid = current_task(loop=self._loop)
self.started.append(tid)
try:
await f()
finally:
self.finished.append(tid)
while not self._can_exit:
await asyncio.sleep(0.01, loop=self._loop)
def test_current_task(loop):
with pytest.raises(RuntimeError):
current_task(loop=loop)
with pytest.raises(RuntimeError):
current_task()
def test_current_task(loop):
with pytest.raises(RuntimeError):
current_task(loop=loop)
with pytest.raises(RuntimeError):
current_task()