From 52911307a0d1a68b623405ea43720b3438b51381 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sat, 12 Oct 2024 11:42:31 +0100 Subject: [PATCH] fix on py3.9 and py3.10 --- tests/test_taskgroups.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/test_taskgroups.py b/tests/test_taskgroups.py index b1def62e..cf12e937 100644 --- a/tests/test_taskgroups.py +++ b/tests/test_taskgroups.py @@ -1549,6 +1549,16 @@ async def in_task_group(task_status: TaskStatus[None]) -> None: assert not tg.cancel_scope.cancel_called +if sys.version_info <= (3, 11): + + def no_other_refs() -> list[object]: + return [sys._getframe(1)] +else: + + def no_other_refs() -> list[object]: + return [] + + async def test_exception_refcycles_direct() -> None: """Test that TaskGroup doesn't keep a reference to the raised ExceptionGroup""" tg = create_task_group() @@ -1564,7 +1574,7 @@ class _Done(Exception): exc = e assert exc is not None - assert gc.get_referrers(exc) == [] + assert gc.get_referrers(exc) == no_other_refs() async def test_exception_refcycles_errors() -> None: @@ -1582,7 +1592,7 @@ class _Done(Exception): exc = excs.exceptions[0] assert isinstance(exc, _Done) - assert gc.get_referrers(exc) == [] + assert gc.get_referrers(exc) == no_other_refs() async def test_exception_refcycles_parent_task() -> None: @@ -1604,7 +1614,7 @@ async def coro_fn() -> None: exc = excs.exceptions[0].exceptions[0] assert isinstance(exc, _Done) - assert gc.get_referrers(exc) == [] + assert gc.get_referrers(exc) == no_other_refs() async def test_exception_refcycles_propagate_cancellation_error() -> None: @@ -1622,7 +1632,7 @@ async def test_exception_refcycles_propagate_cancellation_error() -> None: raise assert isinstance(exc, get_cancelled_exc_class()) - assert gc.get_referrers(exc) == [] + assert gc.get_referrers(exc) == no_other_refs() async def test_exception_refcycles_base_error() -> None: @@ -1641,7 +1651,7 @@ class MyKeyboardInterrupt(KeyboardInterrupt): exc = excs.exceptions[0] assert isinstance(exc, MyKeyboardInterrupt) - assert gc.get_referrers(exc) == [] + assert gc.get_referrers(exc) == no_other_refs() class TestTaskStatusTyping: