pytest
pytest copied to clipboard
Support navigating exceptions chains in pdb
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 (https://github.com/python/cpython/commit/f75cefd402c4c830228d85ca3442377ebaf09454). 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
- CPython github issue for supporting jumping between chained exception in Pdb: https://github.com/python/cpython/issues/106670