Skip to content

Commit

Permalink
Fix forget: check self.lineno, not GLOBAL_PDB.lineno (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Mar 16, 2019
1 parent 9b13902 commit 27eddaf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ def refresh_stack(self):
self.print_current_stack_entry()

def forget(self):
global GLOBAL_PDB
if not hasattr(GLOBAL_PDB, 'lineno'):
if not hasattr(self, 'lineno'):
# Only forget if not used with recursive set_trace.
super(Pdb, self).forget()
self.raise_lineno = {}
Expand Down Expand Up @@ -371,7 +370,6 @@ def _init_pygments(self):
return True

stack_entry_regexp = re.compile(r'(.*?)\(([0-9]+?)\)(.*)', re.DOTALL)
#

def format_stack_entry(self, frame_lineno, lprefix=': '):
entry = super(Pdb, self).format_stack_entry(frame_lineno, lprefix)
Expand Down
44 changes: 44 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,50 @@ def fn():
""")


def test_forget_with_new_pdb():
"""Regression test for having used GLOBAL_PDB in forget.
This caused "AttributeError: 'NewPdb' object has no attribute 'lineno'",
e.g. when pdbpp was used before pytest's debugging plugin was setup, which
then later uses a custom Pdb wrapper.
"""
def fn():
set_trace()

class NewPdb(PdbTest, pdb.Pdb):
def set_trace(self, *args):
print("new_set_trace")
super(NewPdb, self).set_trace(*args)

new_pdb = NewPdb()
new_pdb.set_trace()

check(fn, """
[NUM] > .*fn()
-> class NewPdb(PdbTest, pdb.Pdb):
5 frames hidden .*
# c
new_set_trace
--Return--
[NUM] .*set_trace()->None
-> .*(\\*args)
5 frames hidden .*
# l
NUM .*
NUM .*
NUM .*
NUM .*
NUM .*
NUM .*
NUM .*
NUM .*
NUM .*
NUM .*
NUM .*
# c
""")


def test_single_question_mark():
def fn():
def f2(x, y):
Expand Down

0 comments on commit 27eddaf

Please sign in to comment.