Skip to content

Commit 6f61360

Browse files
committed
fixes after review
1 parent 033120b commit 6f61360

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/_pytest/_code/code.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -593,26 +593,18 @@ def exconly(self, tryshort: bool = False) -> str:
593593
def _get_single_subexc(
594594
eg: BaseExceptionGroup[BaseException],
595595
) -> BaseException | None:
596-
res: BaseException | None = None
597-
for subexc in eg.exceptions:
598-
if res is not None:
599-
return None
600-
601-
if isinstance(subexc, BaseExceptionGroup):
602-
res = _get_single_subexc(subexc)
603-
if res is None:
604-
# there were multiple exceptions in the subgroup
605-
return None
606-
else:
607-
res = subexc
608-
return res
596+
if len(eg.exceptions) != 1:
597+
return None
598+
if isinstance(e := eg.exceptions[0], BaseExceptionGroup):
599+
return _get_single_subexc(e)
600+
return e
609601

610602
if (
611603
tryshort
612604
and isinstance(self.value, BaseExceptionGroup)
613605
and (subexc := _get_single_subexc(self.value)) is not None
614606
):
615-
return f"[in {type(self.value).__name__}] {subexc!r}"
607+
return f"{subexc!r} [single exception in {type(self.value).__name__}]"
616608

617609
lines = format_exception_only(self.type, self.value)
618610
text = "".join(lines)

testing/code/test_excinfo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,15 +1757,15 @@ def test_nested_multiple() -> None:
17571757
"*= short test summary info =*",
17581758
(
17591759
"FAILED test_exceptiongroup_short_summary_info.py::test_base - "
1760-
"[in BaseExceptionGroup] SystemExit('aaaaaaaaaa')"
1760+
"SystemExit('aaaaaaaaaa') [single exception in BaseExceptionGroup]"
17611761
),
17621762
(
17631763
"FAILED test_exceptiongroup_short_summary_info.py::test_nonbase - "
1764-
"[in ExceptionGroup] ValueError('aaaaaaaaaa')"
1764+
"ValueError('aaaaaaaaaa') [single exception in ExceptionGroup]"
17651765
),
17661766
(
17671767
"FAILED test_exceptiongroup_short_summary_info.py::test_nested - "
1768-
"[in ExceptionGroup] ValueError('aaaaaaaaaa')"
1768+
"ValueError('aaaaaaaaaa') [single exception in ExceptionGroup]"
17691769
),
17701770
(
17711771
"FAILED test_exceptiongroup_short_summary_info.py::test_multiple - "

0 commit comments

Comments
 (0)