bpo-24160: Fix breakpoints persistence across multiple pdb sessions (GH-21989)

This commit is contained in:
Irit Katriel 2021-04-02 17:15:21 +01:00 committed by GitHub
parent afd1265058
commit ad442a674c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 144 additions and 13 deletions

View file

@ -213,6 +213,9 @@ def test_pdb_basic_commands():
BAZ
"""
def reset_Breakpoint():
import bdb
bdb.Breakpoint.clearBreakpoints()
def test_pdb_breakpoint_commands():
"""Test basic commands related to breakpoints.
@ -227,10 +230,7 @@ def test_pdb_breakpoint_commands():
First, need to clear bdb state that might be left over from previous tests.
Otherwise, the new breakpoints might get assigned different numbers.
>>> from bdb import Breakpoint
>>> Breakpoint.next = 1
>>> Breakpoint.bplist = {}
>>> Breakpoint.bpbynumber = [None]
>>> reset_Breakpoint()
Now test the breakpoint commands. NORMALIZE_WHITESPACE is needed because
the breakpoint list outputs a tab for the "stop only" and "ignore next"
@ -323,6 +323,72 @@ def test_pdb_breakpoint_commands():
4
"""
def test_pdb_breakpoints_preserved_across_interactive_sessions():
"""Breakpoints are remembered between interactive sessions
>>> reset_Breakpoint()
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
... 'import test.test_pdb',
... 'break test.test_pdb.do_something',
... 'break test.test_pdb.do_nothing',
... 'break',
... 'continue',
... ]):
... pdb.run('print()')
> <string>(1)<module>()
(Pdb) import test.test_pdb
(Pdb) break test.test_pdb.do_something
Breakpoint 1 at ...test_pdb.py:...
(Pdb) break test.test_pdb.do_nothing
Breakpoint 2 at ...test_pdb.py:...
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at ...test_pdb.py:...
2 breakpoint keep yes at ...test_pdb.py:...
(Pdb) continue
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
... 'break',
... 'break pdb.find_function',
... 'break',
... 'clear 1',
... 'continue',
... ]):
... pdb.run('print()')
> <string>(1)<module>()
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at ...test_pdb.py:...
2 breakpoint keep yes at ...test_pdb.py:...
(Pdb) break pdb.find_function
Breakpoint 3 at ...pdb.py:94
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at ...test_pdb.py:...
2 breakpoint keep yes at ...test_pdb.py:...
3 breakpoint keep yes at ...pdb.py:...
(Pdb) clear 1
Deleted breakpoint 1 at ...test_pdb.py:...
(Pdb) continue
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
... 'break',
... 'clear 2',
... 'clear 3',
... 'continue',
... ]):
... pdb.run('print()')
> <string>(1)<module>()
(Pdb) break
Num Type Disp Enb Where
2 breakpoint keep yes at ...test_pdb.py:...
3 breakpoint keep yes at ...pdb.py:...
(Pdb) clear 2
Deleted breakpoint 2 at ...test_pdb.py:...
(Pdb) clear 3
Deleted breakpoint 3 at ...pdb.py:...
(Pdb) continue
"""
def do_nothing():
pass
@ -699,8 +765,7 @@ def test_next_until_return_at_return_event():
... test_function_2()
... end = 1
>>> from bdb import Breakpoint
>>> Breakpoint.next = 1
>>> reset_Breakpoint()
>>> with PdbTestInput(['break test_function_2',
... 'continue',
... 'return',
@ -1137,7 +1202,7 @@ def test_pdb_next_command_in_generator_for_loop():
> <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function()
-> for i in test_gen():
(Pdb) break test_gen
Breakpoint 6 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1
Breakpoint 1 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1
(Pdb) continue
> <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(2)test_gen()
-> yield 0
@ -1213,6 +1278,7 @@ def test_pdb_issue_20766():
... print('pdb %d: %s' % (i, sess._previous_sigint_handler))
... i += 1
>>> reset_Breakpoint()
>>> with PdbTestInput(['continue',
... 'continue']):
... test_function()