From 0d7dc8377418a0a27570c86f4fc55b06afef17b7 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 2 Dec 2025 16:56:20 +0100 Subject: [PATCH 1/4] don't crash if exceptiongroup has only hidden tb frames --- src/_pytest/_code/code.py | 8 +++++++- testing/code/test_excinfo.py | 9 +++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index add2a493ca7..4cf99a77340 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -1193,9 +1193,15 @@ def repr_excinfo(self, excinfo: ExceptionInfo[BaseException]) -> ExceptionChainR format_exception( type(excinfo.value), excinfo.value, - traceback[0]._rawentry, + traceback[0]._rawentry if traceback else None, ) ) + if not traceback: + reprtraceback.extraline = ( + "All traceback entries are hidden. " + "Pass `--full-trace` to see hidden and internal frames." + ) + else: reprtraceback = self.repr_traceback(excinfo_) reprcrash = excinfo_._getreprcrash() diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 476720f0bbe..89040fb1efa 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -1897,19 +1897,20 @@ def test_nested_multiple() -> None: @pytest.mark.parametrize("tbstyle", ("long", "short", "auto", "line", "native")) -def test_all_entries_hidden(pytester: Pytester, tbstyle: str) -> None: +@pytest.mark.parametrize("group", (True, False)) +def test_all_entries_hidden(pytester: Pytester, tbstyle: str, group: bool) -> None: """Regression test for #10903.""" pytester.makepyfile( - """ + f""" def test(): __tracebackhide__ = True - 1 / 0 + raise {'ExceptionGroup("", [ValueError("bar")])' if group else 'ValueError("bar")'} """ ) result = pytester.runpytest("--tb", tbstyle) assert result.ret == 1 if tbstyle != "line": - result.stdout.fnmatch_lines(["*ZeroDivisionError: division by zero"]) + result.stdout.fnmatch_lines(["*ValueError: bar"]) if tbstyle not in ("line", "native"): result.stdout.fnmatch_lines(["All traceback entries are hidden.*"]) From 5e75d3a07c31863d7fa8d67dfb17c745099eca98 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 2 Dec 2025 17:10:09 +0100 Subject: [PATCH 2/4] add newsfragment --- changelog/13734.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/13734.bugfix.rst diff --git a/changelog/13734.bugfix.rst b/changelog/13734.bugfix.rst new file mode 100644 index 00000000000..de1d7368cd4 --- /dev/null +++ b/changelog/13734.bugfix.rst @@ -0,0 +1 @@ +Fixed crash when a test raises an exceptiongroup with ``__tracebackhide__ = True``. From 32a6eb4cd1e672e49a0dad0969cb745edec9cbde Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 2 Dec 2025 17:11:47 +0100 Subject: [PATCH 3/4] fix py<3.11 --- testing/code/test_excinfo.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 89040fb1efa..919c1c73770 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -1902,6 +1902,9 @@ def test_all_entries_hidden(pytester: Pytester, tbstyle: str, group: bool) -> No """Regression test for #10903.""" pytester.makepyfile( f""" + import sys + if sys.version_info < (3, 11): + from exceptiongroup import ExceptionGroup def test(): __tracebackhide__ = True raise {'ExceptionGroup("", [ValueError("bar")])' if group else 'ValueError("bar")'} From b2b3d06f1b5221dc1faabed7be97509d4fb54523 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 2 Dec 2025 18:29:00 +0100 Subject: [PATCH 4/4] add param ids --- testing/code/test_excinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 919c1c73770..70499fec893 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -1897,7 +1897,7 @@ def test_nested_multiple() -> None: @pytest.mark.parametrize("tbstyle", ("long", "short", "auto", "line", "native")) -@pytest.mark.parametrize("group", (True, False)) +@pytest.mark.parametrize("group", (True, False), ids=("group", "bare")) def test_all_entries_hidden(pytester: Pytester, tbstyle: str, group: bool) -> None: """Regression test for #10903.""" pytester.makepyfile(