Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/_pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def _enter_pdb(node, excinfo, rep):
tw.sep(">", "entering PDB")
tb = _postmortem_traceback(excinfo)
rep._pdbshown = True
sys.last_type, sys.last_value, sys.last_traceback = excinfo._excinfo
post_mortem(tb)
return rep
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I wanted this to use Pdb.user_exception instead, but that would require some adjustments of (mocking) tests.
user_exception would set __exception__ into locals (but only type and value currently (https://bugs.python.org/issue36663)).


Expand Down
4 changes: 4 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def mypdb(*args):
return pdblist

def test_pdb_on_fail(self, testdir, pdblist):
sys.last_type, sys.last_value, sys.last_traceback = (None, None, None)
rep = runpdb_and_get_report(
testdir,
"""
Expand All @@ -100,6 +101,9 @@ def test_func():
assert len(pdblist) == 1
tb = _pytest._code.Traceback(pdblist[0][0])
assert tb[-1].name == "test_func"
assert sys.last_type == AssertionError
assert type(sys.last_value) == AssertionError
assert sys.last_traceback == pdblist[0][0]

def test_pdb_on_xfail(self, testdir, pdblist):
rep = runpdb_and_get_report(
Expand Down