@@ -224,10 +224,6 @@ def test_pdb_basic_commands():
224224 BAZ
225225 """
226226
227- def reset_Breakpoint ():
228- import bdb
229- bdb .Breakpoint .clearBreakpoints ()
230-
231227def test_pdb_breakpoint_commands ():
232228 """Test basic commands related to breakpoints.
233229
@@ -238,11 +234,6 @@ def test_pdb_breakpoint_commands():
238234 ... print(3)
239235 ... print(4)
240236
241- First, need to clear bdb state that might be left over from previous tests.
242- Otherwise, the new breakpoints might get assigned different numbers.
243-
244- >>> reset_Breakpoint()
245-
246237 Now test the breakpoint commands. NORMALIZE_WHITESPACE is needed because
247238 the breakpoint list outputs a tab for the "stop only" and "ignore next"
248239 lines, which we don't want to put in here.
@@ -367,8 +358,6 @@ def test_pdb_breakpoint_commands():
367358
368359def test_pdb_breakpoint_ignore_and_condition ():
369360 """
370- >>> reset_Breakpoint()
371-
372361 >>> def test_function():
373362 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
374363 ... for i in range(5):
@@ -384,26 +373,26 @@ def test_pdb_breakpoint_ignore_and_condition():
384373 ... 'continue',
385374 ... ]):
386375 ... test_function()
387- > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1 ]>(2)test_function()
376+ > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0 ]>(2)test_function()
388377 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
389378 (Pdb) break 4
390- Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1 ]>:4
379+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0 ]>:4
391380 (Pdb) ignore 1 2
392381 Will ignore next 2 crossings of breakpoint 1.
393382 (Pdb) continue
394383 0
395384 1
396- > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1 ]>(4)test_function()
385+ > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0 ]>(4)test_function()
397386 -> print(i)
398387 (Pdb) condition 1 i == 4
399388 New condition set for breakpoint 1.
400389 (Pdb) continue
401390 2
402391 3
403- > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1 ]>(4)test_function()
392+ > <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0 ]>(4)test_function()
404393 -> print(i)
405394 (Pdb) clear 1
406- Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[1 ]>:4
395+ Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_ignore_and_condition[0 ]>:4
407396 (Pdb) continue
408397 4
409398 """
@@ -420,8 +409,6 @@ def test_pdb_breakpoint_on_annotated_function_def():
420409 >>> def foobar[T]() -> int:
421410 ... return 0
422411
423- >>> reset_Breakpoint()
424-
425412 >>> def test_function():
426413 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
427414 ... pass
@@ -433,7 +420,7 @@ def test_pdb_breakpoint_on_annotated_function_def():
433420 ... 'continue',
434421 ... ]):
435422 ... test_function()
436- > <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[4 ]>(2)test_function()
423+ > <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[3 ]>(2)test_function()
437424 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
438425 (Pdb) break foo
439426 Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[0]>:2
@@ -453,8 +440,6 @@ def test_pdb_commands():
453440 ... print(2)
454441 ... print(3)
455442
456- >>> reset_Breakpoint()
457-
458443 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
459444 ... 'b 3',
460445 ... 'commands',
@@ -501,13 +486,6 @@ def test_pdb_breakpoint_with_filename():
501486 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
502487 ... mod2.func88()
503488 ... mod2.func114()
504- ... # Be a good citizen and clean up the mess
505- ... reset_Breakpoint()
506-
507- First, need to clear bdb state that might be left over from previous tests.
508- Otherwise, the new breakpoints might get assigned different numbers.
509-
510- >>> reset_Breakpoint()
511489
512490 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
513491 ... 'break test.test_inspect.inspect_fodder2:90',
@@ -535,7 +513,6 @@ def test_pdb_breakpoint_with_filename():
535513def test_pdb_breakpoint_on_disabled_line ():
536514 """New breakpoint on once disabled line should work
537515
538- >>> reset_Breakpoint()
539516 >>> def test_function():
540517 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
541518 ... for i in range(3):
@@ -552,23 +529,23 @@ def test_pdb_breakpoint_on_disabled_line():
552529 ... 'c'
553530 ... ]):
554531 ... test_function()
555- > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1 ]>(2)test_function()
532+ > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0 ]>(2)test_function()
556533 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
557534 (Pdb) break 5
558- Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1 ]>:5
535+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0 ]>:5
559536 (Pdb) c
560- > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1 ]>(5)test_function()
537+ > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0 ]>(5)test_function()
561538 -> print(j)
562539 (Pdb) clear 1
563- Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1 ]>:5
540+ Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0 ]>:5
564541 (Pdb) break 4
565- Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1 ]>:4
542+ Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0 ]>:4
566543 (Pdb) c
567544 0
568- > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1 ]>(4)test_function()
545+ > <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0 ]>(4)test_function()
569546 -> j = i * 2
570547 (Pdb) clear 2
571- Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[1 ]>:4
548+ Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_disabled_line[0 ]>:4
572549 (Pdb) c
573550 2
574551 4
@@ -577,7 +554,6 @@ def test_pdb_breakpoint_on_disabled_line():
577554def test_pdb_breakpoints_preserved_across_interactive_sessions ():
578555 """Breakpoints are remembered between interactive sessions
579556
580- >>> reset_Breakpoint()
581557 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
582558 ... 'import test.test_pdb',
583559 ... 'break test.test_pdb.do_something',
@@ -662,7 +638,6 @@ def test_pdb_break_anywhere():
662638 >>> def test_function():
663639 ... caller()
664640
665- >>> reset_Breakpoint()
666641 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
667642 ... 'b 3',
668643 ... 'c',
@@ -1776,7 +1751,6 @@ def test_pdb_return_to_different_file():
17761751 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
17771752 ... pprint.pprint(A())
17781753
1779- >>> reset_Breakpoint()
17801754 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
17811755 ... 'b A.__repr__',
17821756 ... 'continue',
@@ -2031,7 +2005,6 @@ def test_next_until_return_at_return_event():
20312005 ... test_function_2()
20322006 ... end = 1
20332007
2034- >>> reset_Breakpoint()
20352008 >>> with PdbTestInput(['break test_function_2',
20362009 ... 'continue',
20372010 ... 'return',
@@ -2501,7 +2474,6 @@ def test_pdb_next_command_in_generator_for_loop():
25012474 ... print('value', i)
25022475 ... x = 123
25032476
2504- >>> reset_Breakpoint()
25052477 >>> with PdbTestInput(['break test_gen',
25062478 ... 'continue',
25072479 ... 'next',
@@ -2584,8 +2556,6 @@ def test_pdb_next_command_subiterator():
25842556def test_pdb_breakpoint_with_throw ():
25852557 """GH-132536: PY_THROW event should not be turned off
25862558
2587- >>> reset_Breakpoint()
2588-
25892559 >>> def gen():
25902560 ... yield 0
25912561
@@ -2604,15 +2574,15 @@ def test_pdb_breakpoint_with_throw():
26042574 ... 'continue',
26052575 ... ]):
26062576 ... test_function()
2607- > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2 ]>(2)test_function()
2577+ > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1 ]>(2)test_function()
26082578 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
26092579 (Pdb) b 7
2610- Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2 ]>:7
2580+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1 ]>:7
26112581 (Pdb) continue
2612- > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2 ]>(7)test_function()
2582+ > <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1 ]>(7)test_function()
26132583 -> pass
26142584 (Pdb) clear 1
2615- Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[2 ]>:7
2585+ Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_with_throw[1 ]>:7
26162586 (Pdb) continue
26172587 """
26182588
@@ -2807,7 +2777,6 @@ def test_pdb_issue_20766():
28072777 ... print('pdb %d: %s' % (i, sess._previous_sigint_handler))
28082778 ... i += 1
28092779
2810- >>> reset_Breakpoint()
28112780 >>> with PdbTestInput(['continue',
28122781 ... 'continue']):
28132782 ... test_function()
@@ -2830,7 +2799,6 @@ def test_pdb_issue_43318():
28302799 ... print(2)
28312800 ... print(3)
28322801 ... print(4)
2833- >>> reset_Breakpoint()
28342802 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
28352803 ... 'break 3',
28362804 ... 'clear <doctest test.test_pdb.test_pdb_issue_43318[0]>:3',
@@ -2867,7 +2835,6 @@ def test_pdb_issue_gh_91742():
28672835 ... about()
28682836
28692837
2870- >>> reset_Breakpoint()
28712838 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
28722839 ... 'step',
28732840 ... 'step',
@@ -2914,7 +2881,6 @@ def test_pdb_issue_gh_94215():
29142881 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
29152882 ... func()
29162883
2917- >>> reset_Breakpoint()
29182884 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
29192885 ... 'step',
29202886 ... 'step',
@@ -3145,8 +3111,6 @@ def test_pdb_f_trace_lines():
31453111
31463112 pdb should work even if f_trace_lines is set to False on some frames.
31473113
3148- >>> reset_Breakpoint()
3149-
31503114 >>> def test_function():
31513115 ... import sys
31523116 ... frame = sys._getframe()
@@ -3159,7 +3123,7 @@ def test_pdb_f_trace_lines():
31593123 ... 'continue'
31603124 ... ]):
31613125 ... test_function()
3162- > <doctest test.test_pdb.test_pdb_f_trace_lines[1 ]>(5)test_function()
3126+ > <doctest test.test_pdb.test_pdb_f_trace_lines[0 ]>(5)test_function()
31633127 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
31643128 (Pdb) continue
31653129 """
@@ -4719,6 +4683,20 @@ def tearDown(test):
47194683 # asyncio features are used.
47204684 _set_event_loop_policy (None )
47214685
4686+ # We should cleanup after each doctest to make sure they are not
4687+ # interfering with each other, especially with two backends.
4688+ # If the pdb instance is tracing from the previous test, it might
4689+ # interfere with the next test.
4690+
4691+ # clear all the breakpoints left
4692+ import bdb
4693+ bdb .Breakpoint .clearBreakpoints ()
4694+
4695+ # Stop tracing and clear the pdb instance cache
4696+ if pdb .Pdb ._last_pdb_instance :
4697+ pdb .Pdb ._last_pdb_instance .stop_trace ()
4698+ pdb .Pdb ._last_pdb_instance = None
4699+
47224700 tests .addTest (
47234701 doctest .DocTestSuite (
47244702 test_pdb ,
0 commit comments