MCPcopy
hub / github.com/pytest-dev/pytest / stringify_exception

Function stringify_exception

src/_pytest/_code/code.py:467–491  ·  view source on GitHub ↗
(
    exc: BaseException, include_subexception_msg: bool = True
)

Source from the content-addressed store, hash-verified

465
466
467def stringify_exception(
468 exc: BaseException, include_subexception_msg: bool = True
469) -> str:
470 try:
471 notes = getattr(exc, "__notes__", [])
472 except KeyError:
473 # Workaround for https://github.com/python/cpython/issues/98778 on
474 # some 3.10 and 3.11 patch versions.
475 HTTPError = getattr(sys.modules.get("urllib.error", None), "HTTPError", ())
476 if sys.version_info < (3, 12) and isinstance(exc, HTTPError):
477 notes = []
478 else: # pragma: no cover
479 # exception not related to above bug, reraise
480 raise
481 if not include_subexception_msg and isinstance(exc, BaseExceptionGroup):
482 message = exc.message
483 else:
484 message = str(exc)
485
486 return "\n".join(
487 [
488 message,
489 *notes,
490 ]
491 )
492
493
494E = TypeVar("E", bound=BaseException, covariant=True)

Callers 3

_check_matchMethod · 0.90
matchMethod · 0.85
_group_containsMethod · 0.85

Calls 2

joinMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected