Skip to content

Commit

Permalink
Update tests/test_catch.py
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
  • Loading branch information
jakkdl and agronholm committed Jul 12, 2023
1 parent 36a9e98 commit 84494ac
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions tests/test_catch.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,15 @@ def test_catch_subclass():
assert isinstance(exceptions[0], KeyError)


def test_async_handler():
import asyncio

from exceptiongroup import ExceptionGroup, catch

def test_async_handler(request):
async def handler(eg):
# Log some stuff, then re-raise
raise eg
pass

async def main():
with catch({TypeError: handler}):
raise ExceptionGroup("message", TypeError("uh-oh"))
def delegate(eg):
coro = handler(eg)
request.addfinalizer(coro.close)
return coro

with pytest.raises(TypeError, match="Exception handler must be a sync function."):
asyncio.run(main())
with catch({TypeError: delegate}):
raise ExceptionGroup("message", TypeError("uh-oh"))

0 comments on commit 84494ac

Please sign in to comment.