From 4f80fea8332af2f8369c50db1eb1bc21c5de2584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Mon, 29 Jan 2024 09:26:15 +0100 Subject: [PATCH] BUG: fix an edge case where ExceptionInfo._stringify_exception could crash pytest.raises --- changelog/11879.bugfix.rst | 1 + src/_pytest/_code/code.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelog/11879.bugfix.rst diff --git a/changelog/11879.bugfix.rst b/changelog/11879.bugfix.rst new file mode 100644 index 000000000..a3666fb5a --- /dev/null +++ b/changelog/11879.bugfix.rst @@ -0,0 +1 @@ +Fix an edge case where ``ExceptionInfo._stringify_exception`` could crash ``pytest.raises``. diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index d99b52366..e5b2ea06b 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -47,6 +47,7 @@ from _pytest._io import TerminalWriter from _pytest._io.saferepr import safeformat from _pytest._io.saferepr import saferepr from _pytest.compat import get_real_func +from _pytest.compat import safe_getattr from _pytest.deprecated import check_ispytest from _pytest.pathlib import absolutepath from _pytest.pathlib import bestrelpath @@ -702,7 +703,7 @@ class ExceptionInfo(Generic[E]): return "\n".join( [ str(exc), - *getattr(exc, "__notes__", []), + *safe_getattr(exc, "__notes__", []), ] )