def test_actxmgr_exception_chained():
@aiotools.actxmgr
async def simple_ctx(msg):
try:
await asyncio.sleep(0)
yield msg
except Exception as e:
await asyncio.sleep(0)
# exception is chained
raise ValueError('bomb2') from e
try:
async with simple_ctx('hello') as msg:
assert msg == 'hello'
raise IndexError('bomb1')
except BaseException as exc:
assert isinstance(exc, ValueError)
assert 'bomb2' == exc.args[0]
assert isinstance(exc.__cause__, IndexError)
assert 'bomb1' == exc.__cause__.args[0]
else:
pytest.fail()
评论列表
文章目录