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

Function _postmortem_exc_or_tb

src/_pytest/debugging.py:368–396  ·  view source on GitHub ↗
(
    excinfo: ExceptionInfo[BaseException],
)

Source from the content-addressed store, hash-verified

366
367
368def _postmortem_exc_or_tb(
369 excinfo: ExceptionInfo[BaseException],
370) -> types.TracebackType | BaseException:
371 from doctest import UnexpectedException
372
373 get_exc = sys.version_info >= (3, 13)
374 if isinstance(excinfo.value, UnexpectedException):
375 # A doctest.UnexpectedException is not useful for post_mortem.
376 # Use the underlying exception instead:
377 underlying_exc = excinfo.value
378 if get_exc:
379 return underlying_exc.exc_info[1]
380
381 return underlying_exc.exc_info[2]
382 elif isinstance(excinfo.value, ConftestImportFailure):
383 # A config.ConftestImportFailure is not useful for post_mortem.
384 # Use the underlying exception instead:
385 cause = excinfo.value.cause
386 if get_exc:
387 return cause
388
389 assert cause.__traceback__ is not None
390 return cause.__traceback__
391 else:
392 assert excinfo._excinfo is not None
393 if get_exc:
394 return excinfo._excinfo[1]
395
396 return excinfo._excinfo[2]
397
398
399def post_mortem(tb_or_exc: types.TracebackType | BaseException) -> None:

Callers 2

pytest_internalerrorMethod · 0.85
_enter_pdbFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected