Skip to content

Support navigating exceptions chains in pdb #12707

@AWhetter

Description

@AWhetter

What's the problem this feature will solve?

If running pytest with --pdb and a chain of exceptions is raised, you can only navigate the bottom exception in the chain. You cannot hop between exceptions in the chain

Describe the solution you'd like

Python 3.13.0a1 added support for jumping between chained exception in Pdb (python/cpython@f75cefd). pdb.post_mortem and pdb.Pdb.interaction must be passed an exception object for this to work. These functions used to accept only a traceback, so that's what pytest is passing currently. If pytest passes an exception instead then exception chains can be navigated. As a proof of concept:

diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py
index 3e1463fff..578150f43 100644
--- a/src/_pytest/debugging.py
+++ b/src/_pytest/debugging.py
@@ -354,7 +354,7 @@ def _enter_pdb(
     tw.sep(">", "traceback")
     rep.toterminal(tw)
     tw.sep(">", "entering PDB")
-    tb = _postmortem_traceback(excinfo)
+    tb = excinfo.value #_postmortem_traceback(excinfo)
     rep._pdbshown = True  # type: ignore[attr-defined]
     post_mortem(tb)
     return rep

Alternative Solutions

I have not looked for alternate solutions.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: debuggingrelated to the debugging builtin plugintype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions