(
excinfo: ExceptionInfo[BaseException],
)
| 366 | |
| 367 | |
| 368 | def _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 | |
| 399 | def post_mortem(tb_or_exc: types.TracebackType | BaseException) -> None: |
no outgoing calls
no test coverage detected