Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/13734.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed crash when a test raises an exceptiongroup with ``__tracebackhide__ = True``.
8 changes: 7 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 8 additions & 4 deletions testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,19 +1897,23 @@ 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), ids=("group", "bare"))
def test_all_entries_hidden(pytester: Pytester, tbstyle: str, group: bool) -> None:
"""Regression test for #10903."""
pytester.makepyfile(
"""
f"""
import sys
if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup
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.*"])

Expand Down