Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Nov 22, 2024
1 parent 033120b commit 6f61360
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
20 changes: 6 additions & 14 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,26 +593,18 @@ def exconly(self, tryshort: bool = False) -> str:
def _get_single_subexc(
eg: BaseExceptionGroup[BaseException],
) -> BaseException | None:
res: BaseException | None = None
for subexc in eg.exceptions:
if res is not None:
return None

if isinstance(subexc, BaseExceptionGroup):
res = _get_single_subexc(subexc)
if res is None:
# there were multiple exceptions in the subgroup
return None
else:
res = subexc
return res
if len(eg.exceptions) != 1:
return None

Check warning on line 597 in src/_pytest/_code/code.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/_code/code.py#L597

Added line #L597 was not covered by tests
if isinstance(e := eg.exceptions[0], BaseExceptionGroup):
return _get_single_subexc(e)
return e

Check warning on line 600 in src/_pytest/_code/code.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/_code/code.py#L599-L600

Added lines #L599 - L600 were not covered by tests

if (
tryshort
and isinstance(self.value, BaseExceptionGroup)
and (subexc := _get_single_subexc(self.value)) is not None
):
return f"[in {type(self.value).__name__}] {subexc!r}"
return f"{subexc!r} [single exception in {type(self.value).__name__}]"

Check warning on line 607 in src/_pytest/_code/code.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/_code/code.py#L607

Added line #L607 was not covered by tests

lines = format_exception_only(self.type, self.value)
text = "".join(lines)
Expand Down
6 changes: 3 additions & 3 deletions testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,15 +1757,15 @@ def test_nested_multiple() -> None:
"*= short test summary info =*",
(
"FAILED test_exceptiongroup_short_summary_info.py::test_base - "
"[in BaseExceptionGroup] SystemExit('aaaaaaaaaa')"
"SystemExit('aaaaaaaaaa') [single exception in BaseExceptionGroup]"
),
(
"FAILED test_exceptiongroup_short_summary_info.py::test_nonbase - "
"[in ExceptionGroup] ValueError('aaaaaaaaaa')"
"ValueError('aaaaaaaaaa') [single exception in ExceptionGroup]"
),
(
"FAILED test_exceptiongroup_short_summary_info.py::test_nested - "
"[in ExceptionGroup] ValueError('aaaaaaaaaa')"
"ValueError('aaaaaaaaaa') [single exception in ExceptionGroup]"
),
(
"FAILED test_exceptiongroup_short_summary_info.py::test_multiple - "
Expand Down

0 comments on commit 6f61360

Please sign in to comment.