BAZ
"""
-def reset_Breakpoint():
- import bdb
- bdb.Breakpoint.clearBreakpoints()
-
def test_pdb_breakpoint_commands():
"""Test basic commands related to breakpoints.
... print(3)
... print(4)
- First, need to clear bdb state that might be left over from previous tests.
- Otherwise, the new breakpoints might get assigned different numbers.
-
- >>> 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"
lines, which we don't want to put in here.
def test_pdb_breakpoint_ignore_and_condition():
"""
- >>> reset_Breakpoint()
-
>>> def test_function():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... for i in range(5):
... 'continue',
... ]):
... test_function()
- > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1]>(2)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0]>(2)test_function()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) break 4
- Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1]>:4
+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0]>:4
(Pdb) ignore 1 2
Will ignore next 2 crossings of breakpoint 1.
(Pdb) continue
0
1
- > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1]>(4)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0]>(4)test_function()
-> print(i)
(Pdb) condition 1 i == 4
New condition set for breakpoint 1.
(Pdb) continue
2
3
- > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1]>(4)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0]>(4)test_function()
-> print(i)
(Pdb) clear 1
- Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1]>:4
+ Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0]>:4
(Pdb) continue
4
"""
>>> def foobar[T]() -> int:
... return 0
- >>> reset_Breakpoint()
-
>>> def test_function():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... pass
... 'continue',
... ]):
... test_function()
- > <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[4]>(2)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[3]>(2)test_function()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) break foo
Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[0]>:2
... print(2)
... print(3)
- >>> reset_Breakpoint()
-
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'b 3',
... 'commands',
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... mod2.func88()
... mod2.func114()
- ... # Be a good citizen and clean up the mess
- ... reset_Breakpoint()
-
- First, need to clear bdb state that might be left over from previous tests.
- Otherwise, the new breakpoints might get assigned different numbers.
-
- >>> reset_Breakpoint()
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
... 'break test.test_inspect.inspect_fodder2:90',
def test_pdb_breakpoint_on_disabled_line():
"""New breakpoint on once disabled line should work
- >>> reset_Breakpoint()
>>> def test_function():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... for i in range(3):
... 'c'
... ]):
... test_function()
- > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1]>(2)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0]>(2)test_function()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) break 5
- Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1]>:5
+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0]>:5
(Pdb) c
- > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1]>(5)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0]>(5)test_function()
-> print(j)
(Pdb) clear 1
- Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1]>:5
+ Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0]>:5
(Pdb) break 4
- Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1]>:4
+ Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0]>:4
(Pdb) c
0
- > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1]>(4)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0]>(4)test_function()
-> j = i * 2
(Pdb) clear 2
- Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1]>:4
+ Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0]>:4
(Pdb) c
2
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',
>>> def test_function():
... caller()
- >>> reset_Breakpoint()
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'b 3',
... 'c',
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... pprint.pprint(A())
- >>> reset_Breakpoint()
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
... 'b A.__repr__',
... 'continue',
... test_function_2()
... end = 1
- >>> reset_Breakpoint()
>>> with PdbTestInput(['break test_function_2',
... 'continue',
... 'return',
... print('value', i)
... x = 123
- >>> reset_Breakpoint()
>>> with PdbTestInput(['break test_gen',
... 'continue',
... 'next',
def test_pdb_breakpoint_with_throw():
"""GH-132536: PY_THROW event should not be turned off
- >>> reset_Breakpoint()
-
>>> def gen():
... yield 0
... 'continue',
... ]):
... test_function()
- > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2]>(2)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1]>(2)test_function()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) b 7
- Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2]>:7
+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1]>:7
(Pdb) continue
- > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2]>(7)test_function()
+ > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1]>(7)test_function()
-> pass
(Pdb) clear 1
- Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2]>:7
+ Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1]>:7
(Pdb) continue
"""
... print('pdb %d: %s' % (i, sess._previous_sigint_handler))
... i += 1
- >>> reset_Breakpoint()
>>> with PdbTestInput(['continue',
... 'continue']):
... test_function()
... print(2)
... print(3)
... print(4)
- >>> reset_Breakpoint()
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'break 3',
... 'clear <doctest test.test_pdb.test_pdb_issue_43318[0]>:3',
... about()
- >>> reset_Breakpoint()
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'step',
... 'step',
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... func()
- >>> reset_Breakpoint()
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'step',
... 'step',
pdb should work even if f_trace_lines is set to False on some frames.
- >>> reset_Breakpoint()
-
>>> def test_function():
... import sys
... frame = sys._getframe()
... 'continue'
... ]):
... test_function()
- > <doctest test.test_pdb.test_pdb_f_trace_lines[1]>(5)test_function()
+ > <doctest test.test_pdb.test_pdb_f_trace_lines[0]>(5)test_function()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) continue
"""
# asyncio features are used.
_set_event_loop_policy(None)
+ # A doctest of pdb could have residues. For example, pdb could still
+ # be running, or breakpoints might be left uncleared. These residues
+ # could potentially interfere with the following test, especially
+ # when we switch backends. Here we clear all the residues to restore
+ # to its pre-test state.
+
+ # clear all the breakpoints left
+ import bdb
+ bdb.Breakpoint.clearBreakpoints()
+
+ # Stop tracing and clear the pdb instance cache
+ if pdb.Pdb._last_pdb_instance:
+ pdb.Pdb._last_pdb_instance.stop_trace()
+ pdb.Pdb._last_pdb_instance = None
+
tests.addTest(
doctest.DocTestSuite(
test_pdb,