https://github.com/pytest-dev/pytest-asyncio/issues/205
New issue
set a default loop exception_handler that warns (similar to -p unraisablehook) #205
Comments
consider the following test: import pytest
import asyncio
@pytest.mark.asyncio
async def test_foo():
def raise_():
raise Exception
asyncio.get_running_loop().call_soon(raise_)
await asyncio.sleep(0) it passes cleanly. However if you explicitly collect any errors: import pytest
import asyncio
@pytest.mark.asyncio
async def test_foo():
loop = asyncio.get_running_loop()
old_exception_handler = loop.get_exception_handler()
exceptions = []
def exception_handler(*args, **kwargs):
exceptions.append((args, kwargs))
loop.set_exception_handler(exception_handler)
try:
def raise_():
raise Exception
asyncio.get_running_loop().call_soon(raise_)
await asyncio.sleep(0)
assert exceptions == []
finally:
loop.set_exception_handler(old_exception_handler)
|
沒有留言:
張貼留言