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

Method from_exception

src/_pytest/_code/code.py:522–549  ·  view source on GitHub ↗

Return an ExceptionInfo for an existing exception. The exception must have a non-``None`` ``__traceback__`` attribute, otherwise this function fails with an assertion error. This means that the exception must have been raised, or added a traceback with the :py:meth:`

(
        cls,
        # Ignoring error: "Cannot use a covariant type variable as a parameter".
        # This is OK to ignore because this class is (conceptually) readonly.
        # See https://github.com/python/mypy/issues/7049.
        exception: E,  # type: ignore[misc]
        exprinfo: str | None = None,
    )

Source from the content-addressed store, hash-verified

520
521 @classmethod
522 def from_exception(
523 cls,
524 # Ignoring error: "Cannot use a covariant type variable as a parameter".
525 # This is OK to ignore because this class is (conceptually) readonly.
526 # See https://github.com/python/mypy/issues/7049.
527 exception: E, # type: ignore[misc]
528 exprinfo: str | None = None,
529 ) -> ExceptionInfo[E]:
530 """Return an ExceptionInfo for an existing exception.
531
532 The exception must have a non-``None`` ``__traceback__`` attribute,
533 otherwise this function fails with an assertion error. This means that
534 the exception must have been raised, or added a traceback with the
535 :py:meth:`~BaseException.with_traceback()` method.
536
537 :param exprinfo:
538 A text string helping to determine if we should strip
539 ``AssertionError`` from the output. Defaults to the exception
540 message/``__str__()``.
541
542 .. versionadded:: 7.4
543 """
544 assert exception.__traceback__, (
545 "Exceptions passed to ExcInfo.from_exception(...)"
546 " must have a non-None __traceback__."
547 )
548 exc_info = (type(exception), exception, exception.__traceback__)
549 return cls.from_exc_info(exc_info, exprinfo)
550
551 @classmethod
552 def from_exc_info(

Calls 1

from_exc_infoMethod · 0.80