diff --git a/_pytest/pdb.py b/_pytest/pdb.py index 470e13def..c9471401a 100644 --- a/_pytest/pdb.py +++ b/_pytest/pdb.py @@ -70,16 +70,21 @@ class PdbInvoke: tw.sep(">", "traceback") rep.toterminal(tw) tw.sep(">", "entering PDB") - # A doctest.UnexpectedException is not useful for post_mortem. - # Use the underlying exception instead: - if isinstance(call.excinfo.value, py.std.doctest.UnexpectedException): - tb = call.excinfo.value.exc_info[2] - else: - tb = call.excinfo._excinfo[2] + + tb = self._postmortem_traceback(call.excinfo) post_mortem(tb) rep._pdbshown = True return rep + @staticmethod + def _postmortem_traceback(excinfo): + # A doctest.UnexpectedException is not useful for post_mortem. + # Use the underlying exception instead: + if isinstance(excinfo.value, py.std.doctest.UnexpectedException): + return excinfo.value.exc_info[2] + else: + return excinfo._excinfo[2] + def post_mortem(t): pdb = py.std.pdb class Pdb(pdb.Pdb):