diff --git a/CHANGES.rst b/CHANGES.rst index cd0c7f2..8a847a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,7 +8,10 @@ This library adheres to `Semantic Versioning 2.0 `_. - Fixed ``AttributeError: 'PatchedTracebackException' object has no attribute '__cause__'`` on Python 3.10 (only) when a traceback is printed from an exception where an exception - group is set as the cause + group is set as the cause (#33) +- Fixed a loop in exception groups being rendered incorrectly (#35) +- Fixed the patched formatting functions (``format_exception()``etc.) not passing the + ``compact=True`` flag on Python 3.10 like the original functions do **1.0.0rc9** diff --git a/tests/test_formatting.py b/tests/test_formatting.py index 2b95bac..7cfc152 100644 --- a/tests/test_formatting.py +++ b/tests/test_formatting.py @@ -114,6 +114,44 @@ def test_exceptiongroup_as_cause(capsys: CaptureFixture) -> None: ) +def test_exceptiongroup_loop(capsys: CaptureFixture) -> None: + e0 = Exception("e0") + eg0 = ExceptionGroup("eg0", (e0,)) + eg1 = ExceptionGroup("eg1", (eg0,)) + + try: + raise eg0 from eg1 + except ExceptionGroup as exc: + sys.excepthook(type(exc), exc, exc.__traceback__) + + lineno = test_exceptiongroup_loop.__code__.co_firstlineno + 6 + module_prefix = "" if sys.version_info >= (3, 11) else "exceptiongroup." + output = capsys.readouterr().err + assert output == ( + f"""\ + | {module_prefix}ExceptionGroup: eg1 (1 sub-exception) + +-+---------------- 1 ---------------- + | Exception Group Traceback (most recent call last): + | File "{__file__}", line {lineno}, in test_exceptiongroup_loop + | raise eg0 from eg1 + | {module_prefix}ExceptionGroup: eg0 (1 sub-exception) + +-+---------------- 1 ---------------- + | Exception: e0 + +------------------------------------ + +The above exception was the direct cause of the following exception: + + + Exception Group Traceback (most recent call last): + | File "{__file__}", line {lineno}, in test_exceptiongroup_loop + | raise eg0 from eg1 + | {module_prefix}ExceptionGroup: eg0 (1 sub-exception) + +-+---------------- 1 ---------------- + | Exception: e0 + +------------------------------------ +""" + ) + + def test_exceptionhook_format_exception_only(capsys: CaptureFixture) -> None: try: raise_excgroup()