Skip to content

Commit

Permalink
fix if ExceptionGroup not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheukting committed Jun 23, 2022
1 parent c135a23 commit 5e729b8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@

_TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"]

ExceptionGroupTypes: tuple = ()
try:
ExceptionGroupTypes += (ExceptionGroup,)
except NameError:
pass # Is missing for `python<3.10`
try:
from exceptiongroup import ExceptionGroup

ExceptionGroupTypes += (ExceptionGroup,)
except ModuleNotFoundError:
pass # No backport is installed


class Code:
"""Wrapper around Python code objects."""
Expand Down Expand Up @@ -923,7 +935,7 @@ def repr_excinfo(
seen: Set[int] = set()
while e is not None and id(e) not in seen:
seen.add(id(e))
if isinstance(e, ExceptionGroup):
if isinstance(e, ExceptionGroupTypes):
reprtraceback = ReprTracebackNative(
traceback.format_exception(
type(e), e, excinfo.traceback[0]._rawentry
Expand Down

0 comments on commit 5e729b8

Please sign in to comment.