Beispiel #1
0
def event_loop():
    loop = asyncio.new_event_loop()
    # use ErrorContainer to catch otherwise hidden exceptions occurring in async scheduled tasks
    error_container = asyncio_tools.ErrorContainer()
    loop.set_exception_handler(error_container.exception_handler)
    yield loop
    # will fail if exceptions have been silently raised
    loop.run_until_complete(error_container.check())
    loop.close()
async def test_with_error_container():
    error_container = asyncio_tools.ErrorContainer()
    error_container.print_received_exceptions = False
    asyncio.get_event_loop().set_exception_handler(
        error_container.exception_handler)
    # will propagate exception
    asyncio.get_event_loop().call_soon(_exception_raiser)
    with pytest.raises(AssertionError):
        # ensure exception is caught
        await asyncio.create_task(error_container.check())