Skip to content

Commit e3d97d0

Browse files
committed
gh-139721: Add skip message to stop_here for ignored modules
1 parent 96f6941 commit e3d97d0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Lib/pdb.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,13 @@ def curframe_locals(self, value):
521521

522522
# Override Bdb methods
523523

524+
def stop_here(self, frame):
525+
"""Override bdb's stop_here to add message when skipping ignored modules."""
526+
if self.skip and self.is_skipped_module(frame.f_globals.get('__name__', '')):
527+
self.message('[... skipped 1 ignored module(s)]')
528+
return False
529+
return super().stop_here(frame)
530+
524531
def user_call(self, frame, argument_list):
525532
"""This method is called when there is the remote possibility
526533
that we ever need to stop in this function."""

Lib/test/test_pdb.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,7 @@ def test_pdb_skip_modules():
18111811
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
18121812
-> string.capwords('FOO')
18131813
(Pdb) step
1814+
[... skipped 1 ignored module(s)]
18141815
--Return--
18151816
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
18161817
-> string.capwords('FOO')
@@ -1884,6 +1885,7 @@ def test_pdb_skip_modules_with_callback():
18841885
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
18851886
-> mod.foo_pony(callback)
18861887
(Pdb) step
1888+
[... skipped 1 ignored module(s)]
18871889
--Call--
18881890
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(2)callback()
18891891
-> def callback():
@@ -1895,6 +1897,7 @@ def test_pdb_skip_modules_with_callback():
18951897
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()->None
18961898
-> return None
18971899
(Pdb) step
1900+
[... skipped 1 ignored module(s)]
18981901
--Return--
18991902
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None
19001903
-> mod.foo_pony(callback)
@@ -5134,5 +5137,55 @@ def test_ignore_module_navigation():
51345137
"""
51355138

51365139

5140+
def test_ignore_module_stepping():
5141+
"""Test that ignore_module works with step/next commands.
5142+
5143+
>>> def test_stepping():
5144+
... x = 1
5145+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
5146+
... result = ignore_test_middle.middle_func(lambda: x + 1)
5147+
... y = result + 1
5148+
... return y
5149+
5150+
Test step command with ignored modules - should skip into ignored module
5151+
but show skip message:
5152+
5153+
>>> with PdbTestInput([ # doctest: +ELLIPSIS
5154+
... 'ignore_module ignore_test_middle',
5155+
... 'step', # Step to the function call
5156+
... 'step', # Step into call - should skip middle_func
5157+
... 'return', # Return from lambda
5158+
... 'step', # Step to next line
5159+
... 'p y',
5160+
... 'continue',
5161+
... ]):
5162+
... test_stepping()
5163+
> <doctest test.test_pdb.test_ignore_module_stepping[0]>(3)test_stepping()
5164+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
5165+
(Pdb) ignore_module ignore_test_middle
5166+
Ignoring module: ignore_test_middle
5167+
(Pdb) step
5168+
> <doctest test.test_pdb.test_ignore_module_stepping[0]>(4)test_stepping()
5169+
-> result = ignore_test_middle.middle_func(lambda: x + 1)
5170+
(Pdb) step
5171+
[... skipped 1 ignored module(s)]
5172+
--Call--
5173+
> <doctest test.test_pdb.test_ignore_module_stepping[0]>(4)<lambda>()
5174+
-> result = ignore_test_middle.middle_func(lambda: x + 1)
5175+
(Pdb) return
5176+
--Return--
5177+
> <doctest test.test_pdb.test_ignore_module_stepping[0]>(4)<lambda>()->2
5178+
-> result = ignore_test_middle.middle_func(lambda: x + 1)
5179+
(Pdb) step
5180+
[... skipped 1 ignored module(s)]
5181+
> <doctest test.test_pdb.test_ignore_module_stepping[0]>(5)test_stepping()
5182+
-> y = result + 1
5183+
(Pdb) p y
5184+
*** NameError: name 'y' is not defined
5185+
(Pdb) continue
5186+
3
5187+
"""
5188+
5189+
51375190
if __name__ == '__main__':
51385191
unittest.main()

0 commit comments

Comments
 (0)