Skip to content

Commit b82d2f0

Browse files
committed
BUG: fix an edge case where ExceptionInfo._stringify_exception could crash pytest.raises
1 parent 0ac53cc commit b82d2f0

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

changelog/11879.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix an edge case where ``ExceptionInfo._stringify_exception`` could crash ``pytest.raises``.

src/_pytest/_code/code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from _pytest._io.saferepr import safeformat
4848
from _pytest._io.saferepr import saferepr
4949
from _pytest.compat import get_real_func
50+
from _pytest.compat import safe_getattr
5051
from _pytest.deprecated import check_ispytest
5152
from _pytest.pathlib import absolutepath
5253
from _pytest.pathlib import bestrelpath
@@ -702,7 +703,7 @@ def _stringify_exception(self, exc: BaseException) -> str:
702703
return "\n".join(
703704
[
704705
str(exc),
705-
*getattr(exc, "__notes__", []),
706+
*safe_getattr(exc, "__notes__", []),
706707
]
707708
)
708709

0 commit comments

Comments
 (0)