From 84494ace55371908035f522f8c0f5ca9de007f12 Mon Sep 17 00:00:00 2001 From: John Litborn <11260241+jakkdl@users.noreply.github.com> Date: Wed, 12 Jul 2023 17:10:28 +0200 Subject: [PATCH] Update tests/test_catch.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alex Grönholm --- tests/test_catch.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/test_catch.py b/tests/test_catch.py index f0cb835..caf1368 100644 --- a/tests/test_catch.py +++ b/tests/test_catch.py @@ -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"))