blob: 1e8b12a9af0d83522778927d392faccdd3504b72 [file] [log] [blame]
Georg Brandl46b9afc2010-07-30 09:14:20 +00001# A test suite for pdb; not very comprehensive at the moment.
Martin v. Löwis67880cc2012-05-02 07:41:22 +02002
Andrew Svetlovf0efea02013-03-18 10:09:50 -07003import doctest
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07004import os
Georg Brandl6cccb862010-07-30 14:16:43 +00005import pdb
Georg Brandl243ad662009-05-05 09:00:19 +00006import sys
Brett Cannon9529fbf2013-06-15 17:11:25 -04007import types
Serhiy Storchaka19fcffa2020-06-21 11:07:50 +03008import codecs
Georg Brandl6cccb862010-07-30 14:16:43 +00009import unittest
10import subprocess
Senthil Kumaran42d70812012-05-01 10:07:49 +080011import textwrap
Georg Brandl243ad662009-05-05 09:00:19 +000012
Barry Warsaw35425d62017-09-22 12:29:42 -040013from contextlib import ExitStack
14from io import StringIO
Georg Brandl243ad662009-05-05 09:00:19 +000015from test import support
16# This little helper class is essential for testing pdb under doctest.
17from test.test_doctest import _FakeInput
Barry Warsaw35425d62017-09-22 12:29:42 -040018from unittest.mock import patch
Georg Brandl243ad662009-05-05 09:00:19 +000019
20
Georg Brandl9fa2e022009-09-16 16:40:45 +000021class PdbTestInput(object):
22 """Context manager that makes testing Pdb in doctests easier."""
23
24 def __init__(self, input):
25 self.input = input
26
27 def __enter__(self):
28 self.real_stdin = sys.stdin
29 sys.stdin = _FakeInput(self.input)
Brett Cannon31f59292011-02-21 19:29:56 +000030 self.orig_trace = sys.gettrace() if hasattr(sys, 'gettrace') else None
Georg Brandl9fa2e022009-09-16 16:40:45 +000031
32 def __exit__(self, *exc):
33 sys.stdin = self.real_stdin
Brett Cannon31f59292011-02-21 19:29:56 +000034 if self.orig_trace:
35 sys.settrace(self.orig_trace)
Georg Brandl9fa2e022009-09-16 16:40:45 +000036
37
38def test_pdb_displayhook():
39 """This tests the custom displayhook for pdb.
40
41 >>> def test_function(foo, bar):
Łukasz Langa2eb6eca2016-09-09 22:21:17 -070042 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Georg Brandl9fa2e022009-09-16 16:40:45 +000043 ... pass
44
45 >>> with PdbTestInput([
46 ... 'foo',
47 ... 'bar',
48 ... 'for i in range(5): print(i)',
49 ... 'continue',
50 ... ]):
51 ... test_function(1, None)
52 > <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function()
53 -> pass
54 (Pdb) foo
55 1
56 (Pdb) bar
57 (Pdb) for i in range(5): print(i)
58 0
59 1
60 2
61 3
62 4
63 (Pdb) continue
64 """
65
66
Georg Brandl0d089622010-07-30 16:00:46 +000067def test_pdb_basic_commands():
68 """Test the basic commands of pdb.
69
70 >>> def test_function_2(foo, bar='default'):
71 ... print(foo)
72 ... for i in range(5):
73 ... print(i)
74 ... print(bar)
75 ... for i in range(10):
76 ... never_executed
77 ... print('after for')
78 ... print('...')
79 ... return foo.upper()
80
Rémi Lapeyrebf457c72019-05-21 00:17:30 +020081 >>> def test_function3(arg=None, *, kwonly=None):
82 ... pass
83
Rémi Lapeyre45856032019-05-24 22:44:31 +020084 >>> def test_function4(a, b, c, /):
85 ... pass
86
Georg Brandl0d089622010-07-30 16:00:46 +000087 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -070088 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Georg Brandl0d089622010-07-30 16:00:46 +000089 ... ret = test_function_2('baz')
Rémi Lapeyrebf457c72019-05-21 00:17:30 +020090 ... test_function3(kwonly=True)
Rémi Lapeyre45856032019-05-24 22:44:31 +020091 ... test_function4(1, 2, 3)
Georg Brandl0d089622010-07-30 16:00:46 +000092 ... print(ret)
93
94 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
95 ... 'step', # entering the function call
96 ... 'args', # display function args
97 ... 'list', # list function source
98 ... 'bt', # display backtrace
99 ... 'up', # step up to test_function()
100 ... 'down', # step down to test_function_2() again
101 ... 'next', # stepping to print(foo)
102 ... 'next', # stepping to the for loop
103 ... 'step', # stepping into the for loop
104 ... 'until', # continuing until out of the for loop
105 ... 'next', # executing the print(bar)
106 ... 'jump 8', # jump over second for loop
107 ... 'return', # return out of function
108 ... 'retval', # display return value
Rémi Lapeyrebf457c72019-05-21 00:17:30 +0200109 ... 'next', # step to test_function3()
110 ... 'step', # stepping into test_function3()
111 ... 'args', # display function args
Rémi Lapeyre45856032019-05-24 22:44:31 +0200112 ... 'return', # return out of function
113 ... 'next', # step to test_function4()
114 ... 'step', # stepping to test_function4()
115 ... 'args', # display function args
Georg Brandl0d089622010-07-30 16:00:46 +0000116 ... 'continue',
117 ... ]):
118 ... test_function()
Rémi Lapeyre45856032019-05-24 22:44:31 +0200119 > <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function()
Georg Brandl0d089622010-07-30 16:00:46 +0000120 -> ret = test_function_2('baz')
121 (Pdb) step
122 --Call--
123 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
124 -> def test_function_2(foo, bar='default'):
125 (Pdb) args
126 foo = 'baz'
127 bar = 'default'
128 (Pdb) list
129 1 -> def test_function_2(foo, bar='default'):
130 2 print(foo)
131 3 for i in range(5):
132 4 print(i)
133 5 print(bar)
134 6 for i in range(10):
135 7 never_executed
136 8 print('after for')
137 9 print('...')
138 10 return foo.upper()
139 [EOF]
140 (Pdb) bt
141 ...
Rémi Lapeyre45856032019-05-24 22:44:31 +0200142 <doctest test.test_pdb.test_pdb_basic_commands[4]>(25)<module>()
Georg Brandl0d089622010-07-30 16:00:46 +0000143 -> test_function()
Rémi Lapeyre45856032019-05-24 22:44:31 +0200144 <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function()
Georg Brandl0d089622010-07-30 16:00:46 +0000145 -> ret = test_function_2('baz')
146 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
147 -> def test_function_2(foo, bar='default'):
148 (Pdb) up
Rémi Lapeyre45856032019-05-24 22:44:31 +0200149 > <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function()
Georg Brandl0d089622010-07-30 16:00:46 +0000150 -> ret = test_function_2('baz')
151 (Pdb) down
152 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
153 -> def test_function_2(foo, bar='default'):
154 (Pdb) next
155 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(2)test_function_2()
156 -> print(foo)
157 (Pdb) next
158 baz
159 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(3)test_function_2()
160 -> for i in range(5):
161 (Pdb) step
162 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(4)test_function_2()
163 -> print(i)
164 (Pdb) until
165 0
166 1
167 2
168 3
169 4
170 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(5)test_function_2()
171 -> print(bar)
172 (Pdb) next
173 default
174 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(6)test_function_2()
175 -> for i in range(10):
176 (Pdb) jump 8
177 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(8)test_function_2()
178 -> print('after for')
179 (Pdb) return
180 after for
181 ...
182 --Return--
183 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(10)test_function_2()->'BAZ'
184 -> return foo.upper()
185 (Pdb) retval
186 'BAZ'
Rémi Lapeyrebf457c72019-05-21 00:17:30 +0200187 (Pdb) next
Rémi Lapeyre45856032019-05-24 22:44:31 +0200188 > <doctest test.test_pdb.test_pdb_basic_commands[3]>(4)test_function()
Rémi Lapeyrebf457c72019-05-21 00:17:30 +0200189 -> test_function3(kwonly=True)
190 (Pdb) step
191 --Call--
192 > <doctest test.test_pdb.test_pdb_basic_commands[1]>(1)test_function3()
193 -> def test_function3(arg=None, *, kwonly=None):
194 (Pdb) args
195 arg = None
196 kwonly = True
Rémi Lapeyre45856032019-05-24 22:44:31 +0200197 (Pdb) return
198 --Return--
199 > <doctest test.test_pdb.test_pdb_basic_commands[1]>(2)test_function3()->None
200 -> pass
201 (Pdb) next
202 > <doctest test.test_pdb.test_pdb_basic_commands[3]>(5)test_function()
203 -> test_function4(1, 2, 3)
204 (Pdb) step
205 --Call--
206 > <doctest test.test_pdb.test_pdb_basic_commands[2]>(1)test_function4()
207 -> def test_function4(a, b, c, /):
208 (Pdb) args
209 a = 1
210 b = 2
211 c = 3
Georg Brandl0d089622010-07-30 16:00:46 +0000212 (Pdb) continue
213 BAZ
214 """
215
216
217def test_pdb_breakpoint_commands():
218 """Test basic commands related to breakpoints.
219
220 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700221 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Georg Brandl0d089622010-07-30 16:00:46 +0000222 ... print(1)
223 ... print(2)
224 ... print(3)
225 ... print(4)
226
227 First, need to clear bdb state that might be left over from previous tests.
228 Otherwise, the new breakpoints might get assigned different numbers.
229
230 >>> from bdb import Breakpoint
231 >>> Breakpoint.next = 1
232 >>> Breakpoint.bplist = {}
233 >>> Breakpoint.bpbynumber = [None]
234
235 Now test the breakpoint commands. NORMALIZE_WHITESPACE is needed because
236 the breakpoint list outputs a tab for the "stop only" and "ignore next"
237 lines, which we don't want to put in here.
238
239 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
240 ... 'break 3',
241 ... 'disable 1',
242 ... 'ignore 1 10',
243 ... 'condition 1 1 < 2',
244 ... 'break 4',
Senthil Kumaran6f107042010-11-29 11:54:17 +0000245 ... 'break 4',
246 ... 'break',
247 ... 'clear 3',
Georg Brandl0d089622010-07-30 16:00:46 +0000248 ... 'break',
249 ... 'condition 1',
250 ... 'enable 1',
251 ... 'clear 1',
252 ... 'commands 2',
R David Murray78d692f2013-10-10 17:23:26 -0400253 ... 'p "42"',
254 ... 'print("42", 7*6)', # Issue 18764 (not about breakpoints)
Georg Brandl0d089622010-07-30 16:00:46 +0000255 ... 'end',
256 ... 'continue', # will stop at breakpoint 2 (line 4)
257 ... 'clear', # clear all!
258 ... 'y',
259 ... 'tbreak 5',
260 ... 'continue', # will stop at temporary breakpoint
261 ... 'break', # make sure breakpoint is gone
262 ... 'continue',
263 ... ]):
264 ... test_function()
265 > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(3)test_function()
266 -> print(1)
267 (Pdb) break 3
268 Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
269 (Pdb) disable 1
270 Disabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
271 (Pdb) ignore 1 10
272 Will ignore next 10 crossings of breakpoint 1.
273 (Pdb) condition 1 1 < 2
274 New condition set for breakpoint 1.
275 (Pdb) break 4
276 Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
Senthil Kumaran6f107042010-11-29 11:54:17 +0000277 (Pdb) break 4
278 Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
279 (Pdb) break
280 Num Type Disp Enb Where
281 1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
282 stop only if 1 < 2
283 ignore next 10 hits
284 2 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
285 3 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
286 (Pdb) clear 3
287 Deleted breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
Georg Brandl0d089622010-07-30 16:00:46 +0000288 (Pdb) break
289 Num Type Disp Enb Where
290 1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
291 stop only if 1 < 2
292 ignore next 10 hits
293 2 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
294 (Pdb) condition 1
295 Breakpoint 1 is now unconditional.
296 (Pdb) enable 1
297 Enabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
298 (Pdb) clear 1
299 Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
300 (Pdb) commands 2
R David Murray78d692f2013-10-10 17:23:26 -0400301 (com) p "42"
302 (com) print("42", 7*6)
Georg Brandl0d089622010-07-30 16:00:46 +0000303 (com) end
304 (Pdb) continue
305 1
R David Murray78d692f2013-10-10 17:23:26 -0400306 '42'
307 42 42
Georg Brandl0d089622010-07-30 16:00:46 +0000308 > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function()
309 -> print(2)
310 (Pdb) clear
311 Clear all breaks? y
312 Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
313 (Pdb) tbreak 5
Senthil Kumaran6f107042010-11-29 11:54:17 +0000314 Breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
Georg Brandl0d089622010-07-30 16:00:46 +0000315 (Pdb) continue
316 2
Senthil Kumaran6f107042010-11-29 11:54:17 +0000317 Deleted breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
Georg Brandl0d089622010-07-30 16:00:46 +0000318 > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function()
319 -> print(3)
320 (Pdb) break
321 (Pdb) continue
322 3
323 4
324 """
325
326
Georg Brandle59ca2a2010-07-30 17:04:28 +0000327def do_nothing():
328 pass
329
330def do_something():
331 print(42)
332
333def test_list_commands():
334 """Test the list and source commands of pdb.
335
336 >>> def test_function_2(foo):
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000337 ... import test.test_pdb
338 ... test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000339 ... 'some...'
340 ... 'more...'
341 ... 'code...'
342 ... 'to...'
343 ... 'make...'
344 ... 'a...'
345 ... 'long...'
346 ... 'listing...'
347 ... 'useful...'
348 ... '...'
349 ... '...'
350 ... return foo
351
352 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700353 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000354 ... ret = test_function_2('baz')
355
356 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
357 ... 'list', # list first function
358 ... 'step', # step into second function
359 ... 'list', # list second function
360 ... 'list', # continue listing to EOF
361 ... 'list 1,3', # list specific lines
362 ... 'list x', # invalid argument
363 ... 'next', # step to import
364 ... 'next', # step over import
365 ... 'step', # step into do_nothing
366 ... 'longlist', # list all lines
367 ... 'source do_something', # list all lines of function
Georg Brandlcdf66a92010-07-30 18:15:16 +0000368 ... 'source fooxxx', # something that doesn't exit
Georg Brandle59ca2a2010-07-30 17:04:28 +0000369 ... 'continue',
370 ... ]):
371 ... test_function()
372 > <doctest test.test_pdb.test_list_commands[1]>(3)test_function()
373 -> ret = test_function_2('baz')
374 (Pdb) list
375 1 def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700376 2 import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000377 3 -> ret = test_function_2('baz')
378 [EOF]
379 (Pdb) step
380 --Call--
381 > <doctest test.test_pdb.test_list_commands[0]>(1)test_function_2()
382 -> def test_function_2(foo):
383 (Pdb) list
384 1 -> def test_function_2(foo):
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000385 2 import test.test_pdb
386 3 test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000387 4 'some...'
388 5 'more...'
389 6 'code...'
390 7 'to...'
391 8 'make...'
392 9 'a...'
393 10 'long...'
394 11 'listing...'
395 (Pdb) list
396 12 'useful...'
397 13 '...'
398 14 '...'
399 15 return foo
400 [EOF]
401 (Pdb) list 1,3
402 1 -> def test_function_2(foo):
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000403 2 import test.test_pdb
404 3 test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000405 (Pdb) list x
406 *** ...
407 (Pdb) next
408 > <doctest test.test_pdb.test_list_commands[0]>(2)test_function_2()
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000409 -> import test.test_pdb
Georg Brandle59ca2a2010-07-30 17:04:28 +0000410 (Pdb) next
411 > <doctest test.test_pdb.test_list_commands[0]>(3)test_function_2()
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000412 -> test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000413 (Pdb) step
414 --Call--
Georg Brandle1e8df12010-07-31 08:14:16 +0000415 > ...test_pdb.py(...)do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000416 -> def do_nothing():
417 (Pdb) longlist
418 ... -> def do_nothing():
419 ... pass
420 (Pdb) source do_something
421 ... def do_something():
422 ... print(42)
Georg Brandlcdf66a92010-07-30 18:15:16 +0000423 (Pdb) source fooxxx
424 *** ...
Georg Brandle59ca2a2010-07-30 17:04:28 +0000425 (Pdb) continue
426 """
427
428
Georg Brandl0a9c3e92010-07-30 18:46:38 +0000429def test_post_mortem():
430 """Test post mortem traceback debugging.
431
432 >>> def test_function_2():
433 ... try:
434 ... 1/0
435 ... finally:
436 ... print('Exception!')
437
438 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700439 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Georg Brandl0a9c3e92010-07-30 18:46:38 +0000440 ... test_function_2()
441 ... print('Not reached.')
442
443 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
444 ... 'next', # step over exception-raising call
445 ... 'bt', # get a backtrace
446 ... 'list', # list code of test_function()
447 ... 'down', # step into test_function_2()
448 ... 'list', # list code of test_function_2()
449 ... 'continue',
450 ... ]):
451 ... try:
452 ... test_function()
453 ... except ZeroDivisionError:
454 ... print('Correctly reraised.')
455 > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
456 -> test_function_2()
457 (Pdb) next
458 Exception!
459 ZeroDivisionError: division by zero
460 > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
461 -> test_function_2()
462 (Pdb) bt
463 ...
464 <doctest test.test_pdb.test_post_mortem[2]>(10)<module>()
465 -> test_function()
466 > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
467 -> test_function_2()
468 <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
469 -> 1/0
470 (Pdb) list
471 1 def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700472 2 import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Georg Brandl0a9c3e92010-07-30 18:46:38 +0000473 3 -> test_function_2()
474 4 print('Not reached.')
475 [EOF]
476 (Pdb) down
477 > <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
478 -> 1/0
479 (Pdb) list
480 1 def test_function_2():
481 2 try:
482 3 >> 1/0
483 4 finally:
484 5 -> print('Exception!')
485 [EOF]
486 (Pdb) continue
487 Correctly reraised.
488 """
489
490
Georg Brandl243ad662009-05-05 09:00:19 +0000491def test_pdb_skip_modules():
492 """This illustrates the simple case of module skipping.
493
494 >>> def skip_module():
495 ... import string
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700496 ... import pdb; pdb.Pdb(skip=['stri*'], nosigint=True, readrc=False).set_trace()
Georg Brandl243ad662009-05-05 09:00:19 +0000497 ... string.capwords('FOO')
Georg Brandl243ad662009-05-05 09:00:19 +0000498
Georg Brandl9fa2e022009-09-16 16:40:45 +0000499 >>> with PdbTestInput([
500 ... 'step',
501 ... 'continue',
502 ... ]):
Georg Brandl243ad662009-05-05 09:00:19 +0000503 ... skip_module()
Georg Brandl243ad662009-05-05 09:00:19 +0000504 > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
505 -> string.capwords('FOO')
506 (Pdb) step
507 --Return--
508 > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
509 -> string.capwords('FOO')
510 (Pdb) continue
Georg Brandl9fa2e022009-09-16 16:40:45 +0000511 """
Georg Brandl243ad662009-05-05 09:00:19 +0000512
513
514# Module for testing skipping of module that makes a callback
Brett Cannon9529fbf2013-06-15 17:11:25 -0400515mod = types.ModuleType('module_to_skip')
Georg Brandl243ad662009-05-05 09:00:19 +0000516exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__)
517
518
519def test_pdb_skip_modules_with_callback():
520 """This illustrates skipping of modules that call into other code.
521
522 >>> def skip_module():
523 ... def callback():
524 ... return None
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700525 ... import pdb; pdb.Pdb(skip=['module_to_skip*'], nosigint=True, readrc=False).set_trace()
Georg Brandl243ad662009-05-05 09:00:19 +0000526 ... mod.foo_pony(callback)
Georg Brandl243ad662009-05-05 09:00:19 +0000527
Georg Brandl9fa2e022009-09-16 16:40:45 +0000528 >>> with PdbTestInput([
529 ... 'step',
530 ... 'step',
531 ... 'step',
532 ... 'step',
533 ... 'step',
534 ... 'continue',
535 ... ]):
Georg Brandl243ad662009-05-05 09:00:19 +0000536 ... skip_module()
Georg Brandl9fa2e022009-09-16 16:40:45 +0000537 ... pass # provides something to "step" to
Georg Brandl243ad662009-05-05 09:00:19 +0000538 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
539 -> mod.foo_pony(callback)
540 (Pdb) step
541 --Call--
542 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(2)callback()
543 -> def callback():
544 (Pdb) step
545 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()
546 -> return None
547 (Pdb) step
548 --Return--
549 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()->None
550 -> return None
551 (Pdb) step
552 --Return--
553 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None
554 -> mod.foo_pony(callback)
555 (Pdb) step
Georg Brandl9fa2e022009-09-16 16:40:45 +0000556 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[1]>(10)<module>()
557 -> pass # provides something to "step" to
Georg Brandl243ad662009-05-05 09:00:19 +0000558 (Pdb) continue
Georg Brandl9fa2e022009-09-16 16:40:45 +0000559 """
Georg Brandl243ad662009-05-05 09:00:19 +0000560
561
Georg Brandl3f940892010-07-30 10:29:19 +0000562def test_pdb_continue_in_bottomframe():
563 """Test that "continue" and "next" work properly in bottom frame (issue #5294).
564
565 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700566 ... import pdb, sys; inst = pdb.Pdb(nosigint=True, readrc=False)
Georg Brandl3f940892010-07-30 10:29:19 +0000567 ... inst.set_trace()
568 ... inst.botframe = sys._getframe() # hackery to get the right botframe
569 ... print(1)
570 ... print(2)
571 ... print(3)
572 ... print(4)
573
Georg Brandl7410dd12010-07-30 12:01:20 +0000574 >>> with PdbTestInput([ # doctest: +ELLIPSIS
Georg Brandl3f940892010-07-30 10:29:19 +0000575 ... 'next',
576 ... 'break 7',
577 ... 'continue',
578 ... 'next',
579 ... 'continue',
580 ... 'continue',
581 ... ]):
582 ... test_function()
583 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(4)test_function()
584 -> inst.botframe = sys._getframe() # hackery to get the right botframe
585 (Pdb) next
586 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(5)test_function()
587 -> print(1)
588 (Pdb) break 7
Georg Brandl7410dd12010-07-30 12:01:20 +0000589 Breakpoint ... at <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>:7
Georg Brandl3f940892010-07-30 10:29:19 +0000590 (Pdb) continue
591 1
592 2
593 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(7)test_function()
594 -> print(3)
595 (Pdb) next
596 3
597 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(8)test_function()
598 -> print(4)
599 (Pdb) continue
600 4
601 """
602
603
Georg Brandl46b9afc2010-07-30 09:14:20 +0000604def pdb_invoke(method, arg):
605 """Run pdb.method(arg)."""
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700606 getattr(pdb.Pdb(nosigint=True, readrc=False), method)(arg)
Georg Brandl46b9afc2010-07-30 09:14:20 +0000607
608
609def test_pdb_run_with_incorrect_argument():
610 """Testing run and runeval with incorrect first argument.
611
612 >>> pti = PdbTestInput(['continue',])
613 >>> with pti:
614 ... pdb_invoke('run', lambda x: x)
615 Traceback (most recent call last):
616 TypeError: exec() arg 1 must be a string, bytes or code object
617
618 >>> with pti:
619 ... pdb_invoke('runeval', lambda x: x)
620 Traceback (most recent call last):
621 TypeError: eval() arg 1 must be a string, bytes or code object
622 """
623
624
625def test_pdb_run_with_code_object():
626 """Testing run and runeval with code object as a first argument.
627
Georg Brandle1e8df12010-07-31 08:14:16 +0000628 >>> with PdbTestInput(['step','x', 'continue']): # doctest: +ELLIPSIS
Georg Brandl46b9afc2010-07-30 09:14:20 +0000629 ... pdb_invoke('run', compile('x=1', '<string>', 'exec'))
Georg Brandle1e8df12010-07-31 08:14:16 +0000630 > <string>(1)<module>()...
Georg Brandl46b9afc2010-07-30 09:14:20 +0000631 (Pdb) step
632 --Return--
633 > <string>(1)<module>()->None
634 (Pdb) x
635 1
636 (Pdb) continue
637
638 >>> with PdbTestInput(['x', 'continue']):
639 ... x=0
640 ... pdb_invoke('runeval', compile('x+1', '<string>', 'eval'))
641 > <string>(1)<module>()->None
642 (Pdb) x
643 1
644 (Pdb) continue
645 """
646
Guido van Rossum8820c232013-11-21 11:30:06 -0800647def test_next_until_return_at_return_event():
648 """Test that pdb stops after a next/until/return issued at a return debug event.
649
650 >>> def test_function_2():
651 ... x = 1
652 ... x = 2
653
654 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700655 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Guido van Rossum8820c232013-11-21 11:30:06 -0800656 ... test_function_2()
657 ... test_function_2()
658 ... test_function_2()
659 ... end = 1
660
Antoine Pitrouc04d4682014-08-11 21:40:38 -0400661 >>> from bdb import Breakpoint
662 >>> Breakpoint.next = 1
Guido van Rossum8820c232013-11-21 11:30:06 -0800663 >>> with PdbTestInput(['break test_function_2',
664 ... 'continue',
665 ... 'return',
666 ... 'next',
667 ... 'continue',
668 ... 'return',
669 ... 'until',
670 ... 'continue',
671 ... 'return',
672 ... 'return',
673 ... 'continue']):
674 ... test_function()
675 > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(3)test_function()
676 -> test_function_2()
677 (Pdb) break test_function_2
678 Breakpoint 1 at <doctest test.test_pdb.test_next_until_return_at_return_event[0]>:1
679 (Pdb) continue
680 > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2()
681 -> x = 1
682 (Pdb) return
683 --Return--
684 > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(3)test_function_2()->None
685 -> x = 2
686 (Pdb) next
687 > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(4)test_function()
688 -> test_function_2()
689 (Pdb) continue
690 > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2()
691 -> x = 1
692 (Pdb) return
693 --Return--
694 > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(3)test_function_2()->None
695 -> x = 2
696 (Pdb) until
697 > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(5)test_function()
698 -> test_function_2()
699 (Pdb) continue
700 > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2()
701 -> x = 1
702 (Pdb) return
703 --Return--
704 > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(3)test_function_2()->None
705 -> x = 2
706 (Pdb) return
707 > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(6)test_function()
708 -> end = 1
709 (Pdb) continue
710 """
711
712def test_pdb_next_command_for_generator():
713 """Testing skip unwindng stack on yield for generators for "next" command
714
715 >>> def test_gen():
716 ... yield 0
717 ... return 1
718 ... yield 2
719
720 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700721 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Guido van Rossum8820c232013-11-21 11:30:06 -0800722 ... it = test_gen()
723 ... try:
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300724 ... if next(it) != 0:
725 ... raise AssertionError
Guido van Rossum8820c232013-11-21 11:30:06 -0800726 ... next(it)
727 ... except StopIteration as ex:
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300728 ... if ex.value != 1:
729 ... raise AssertionError
Guido van Rossum8820c232013-11-21 11:30:06 -0800730 ... print("finished")
731
732 >>> with PdbTestInput(['step',
733 ... 'step',
734 ... 'step',
735 ... 'next',
736 ... 'next',
737 ... 'step',
738 ... 'step',
739 ... 'continue']):
740 ... test_function()
741 > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(3)test_function()
742 -> it = test_gen()
743 (Pdb) step
744 > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(4)test_function()
745 -> try:
746 (Pdb) step
747 > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(5)test_function()
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300748 -> if next(it) != 0:
Guido van Rossum8820c232013-11-21 11:30:06 -0800749 (Pdb) step
750 --Call--
751 > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(1)test_gen()
752 -> def test_gen():
753 (Pdb) next
754 > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(2)test_gen()
755 -> yield 0
756 (Pdb) next
757 > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(3)test_gen()
758 -> return 1
759 (Pdb) step
760 --Return--
761 > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(3)test_gen()->1
762 -> return 1
763 (Pdb) step
764 StopIteration: 1
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300765 > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(7)test_function()
Guido van Rossum8820c232013-11-21 11:30:06 -0800766 -> next(it)
767 (Pdb) continue
768 finished
769 """
770
Pablo Galindo46877022018-01-29 00:25:05 +0000771def test_pdb_next_command_for_coroutine():
772 """Testing skip unwindng stack on yield for coroutines for "next" command
773
774 >>> import asyncio
775
776 >>> async def test_coro():
777 ... await asyncio.sleep(0)
778 ... await asyncio.sleep(0)
779 ... await asyncio.sleep(0)
780
781 >>> async def test_main():
782 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
783 ... await test_coro()
784
785 >>> def test_function():
Pablo Galindoc7ab5812018-01-29 01:31:00 +0000786 ... loop = asyncio.new_event_loop()
Pablo Galindo46877022018-01-29 00:25:05 +0000787 ... loop.run_until_complete(test_main())
788 ... loop.close()
Brett Cannon8425de42018-06-01 20:34:09 -0700789 ... asyncio.set_event_loop_policy(None)
Pablo Galindo46877022018-01-29 00:25:05 +0000790 ... print("finished")
791
792 >>> with PdbTestInput(['step',
793 ... 'step',
794 ... 'next',
795 ... 'next',
796 ... 'next',
797 ... 'step',
798 ... 'continue']):
799 ... test_function()
800 > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()
801 -> await test_coro()
802 (Pdb) step
803 --Call--
804 > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(1)test_coro()
805 -> async def test_coro():
806 (Pdb) step
807 > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(2)test_coro()
808 -> await asyncio.sleep(0)
809 (Pdb) next
810 > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(3)test_coro()
811 -> await asyncio.sleep(0)
812 (Pdb) next
813 > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(4)test_coro()
814 -> await asyncio.sleep(0)
815 (Pdb) next
816 Internal StopIteration
817 > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()
818 -> await test_coro()
819 (Pdb) step
820 --Return--
821 > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()->None
822 -> await test_coro()
823 (Pdb) continue
824 finished
825 """
826
Yury Selivanov9ee1bf92018-01-28 22:43:46 -0500827def test_pdb_next_command_for_asyncgen():
828 """Testing skip unwindng stack on yield for coroutines for "next" command
829
830 >>> import asyncio
831
832 >>> async def agen():
833 ... yield 1
834 ... await asyncio.sleep(0)
835 ... yield 2
836
837 >>> async def test_coro():
838 ... async for x in agen():
839 ... print(x)
840
841 >>> async def test_main():
842 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
843 ... await test_coro()
844
845 >>> def test_function():
846 ... loop = asyncio.new_event_loop()
847 ... loop.run_until_complete(test_main())
848 ... loop.close()
Brett Cannon8425de42018-06-01 20:34:09 -0700849 ... asyncio.set_event_loop_policy(None)
Yury Selivanov9ee1bf92018-01-28 22:43:46 -0500850 ... print("finished")
851
852 >>> with PdbTestInput(['step',
853 ... 'step',
854 ... 'next',
855 ... 'next',
856 ... 'step',
857 ... 'next',
858 ... 'continue']):
859 ... test_function()
860 > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[3]>(3)test_main()
861 -> await test_coro()
862 (Pdb) step
863 --Call--
864 > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(1)test_coro()
865 -> async def test_coro():
866 (Pdb) step
867 > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro()
868 -> async for x in agen():
869 (Pdb) next
870 > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(3)test_coro()
871 -> print(x)
872 (Pdb) next
873 1
874 > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro()
875 -> async for x in agen():
876 (Pdb) step
877 --Call--
878 > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(2)agen()
879 -> yield 1
880 (Pdb) next
881 > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(3)agen()
882 -> await asyncio.sleep(0)
883 (Pdb) continue
884 2
885 finished
886 """
887
Guido van Rossum8820c232013-11-21 11:30:06 -0800888def test_pdb_return_command_for_generator():
889 """Testing no unwindng stack on yield for generators
890 for "return" command
891
892 >>> def test_gen():
893 ... yield 0
894 ... return 1
895 ... yield 2
896
897 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700898 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Guido van Rossum8820c232013-11-21 11:30:06 -0800899 ... it = test_gen()
900 ... try:
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300901 ... if next(it) != 0:
902 ... raise AssertionError
Guido van Rossum8820c232013-11-21 11:30:06 -0800903 ... next(it)
904 ... except StopIteration as ex:
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300905 ... if ex.value != 1:
906 ... raise AssertionError
Guido van Rossum8820c232013-11-21 11:30:06 -0800907 ... print("finished")
908
909 >>> with PdbTestInput(['step',
910 ... 'step',
911 ... 'step',
912 ... 'return',
913 ... 'step',
914 ... 'step',
915 ... 'continue']):
916 ... test_function()
917 > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(3)test_function()
918 -> it = test_gen()
919 (Pdb) step
920 > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(4)test_function()
921 -> try:
922 (Pdb) step
923 > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(5)test_function()
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300924 -> if next(it) != 0:
Guido van Rossum8820c232013-11-21 11:30:06 -0800925 (Pdb) step
926 --Call--
927 > <doctest test.test_pdb.test_pdb_return_command_for_generator[0]>(1)test_gen()
928 -> def test_gen():
929 (Pdb) return
930 StopIteration: 1
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300931 > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(7)test_function()
Guido van Rossum8820c232013-11-21 11:30:06 -0800932 -> next(it)
933 (Pdb) step
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300934 > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(8)test_function()
Guido van Rossum8820c232013-11-21 11:30:06 -0800935 -> except StopIteration as ex:
936 (Pdb) step
Serhiy Storchakaa16de5d2015-04-01 16:58:19 +0300937 > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(9)test_function()
938 -> if ex.value != 1:
Guido van Rossum8820c232013-11-21 11:30:06 -0800939 (Pdb) continue
940 finished
941 """
942
Pablo Galindoc7ab5812018-01-29 01:31:00 +0000943def test_pdb_return_command_for_coroutine():
944 """Testing no unwindng stack on yield for coroutines for "return" command
945
946 >>> import asyncio
947
948 >>> async def test_coro():
949 ... await asyncio.sleep(0)
950 ... await asyncio.sleep(0)
951 ... await asyncio.sleep(0)
952
953 >>> async def test_main():
954 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
955 ... await test_coro()
956
957 >>> def test_function():
958 ... loop = asyncio.new_event_loop()
959 ... loop.run_until_complete(test_main())
960 ... loop.close()
Brett Cannon8425de42018-06-01 20:34:09 -0700961 ... asyncio.set_event_loop_policy(None)
Pablo Galindoc7ab5812018-01-29 01:31:00 +0000962 ... print("finished")
963
964 >>> with PdbTestInput(['step',
965 ... 'step',
966 ... 'next',
967 ... 'continue']):
968 ... test_function()
969 > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[2]>(3)test_main()
970 -> await test_coro()
971 (Pdb) step
972 --Call--
973 > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(1)test_coro()
974 -> async def test_coro():
975 (Pdb) step
976 > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(2)test_coro()
977 -> await asyncio.sleep(0)
978 (Pdb) next
979 > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(3)test_coro()
980 -> await asyncio.sleep(0)
981 (Pdb) continue
982 finished
983 """
984
Guido van Rossum8820c232013-11-21 11:30:06 -0800985def test_pdb_until_command_for_generator():
986 """Testing no unwindng stack on yield for generators
Min ho Kimc4cacc82019-07-31 08:16:13 +1000987 for "until" command if target breakpoint is not reached
Guido van Rossum8820c232013-11-21 11:30:06 -0800988
989 >>> def test_gen():
990 ... yield 0
991 ... yield 1
992 ... yield 2
993
994 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -0700995 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Guido van Rossum8820c232013-11-21 11:30:06 -0800996 ... for i in test_gen():
997 ... print(i)
998 ... print("finished")
999
1000 >>> with PdbTestInput(['step',
1001 ... 'until 4',
1002 ... 'step',
1003 ... 'step',
1004 ... 'continue']):
1005 ... test_function()
1006 > <doctest test.test_pdb.test_pdb_until_command_for_generator[1]>(3)test_function()
1007 -> for i in test_gen():
1008 (Pdb) step
1009 --Call--
1010 > <doctest test.test_pdb.test_pdb_until_command_for_generator[0]>(1)test_gen()
1011 -> def test_gen():
1012 (Pdb) until 4
1013 0
1014 1
1015 > <doctest test.test_pdb.test_pdb_until_command_for_generator[0]>(4)test_gen()
1016 -> yield 2
1017 (Pdb) step
1018 --Return--
1019 > <doctest test.test_pdb.test_pdb_until_command_for_generator[0]>(4)test_gen()->2
1020 -> yield 2
1021 (Pdb) step
1022 > <doctest test.test_pdb.test_pdb_until_command_for_generator[1]>(4)test_function()
1023 -> print(i)
1024 (Pdb) continue
1025 2
1026 finished
1027 """
1028
Andrew Svetlov4f4ef0a2018-01-29 16:17:45 +02001029def test_pdb_until_command_for_coroutine():
1030 """Testing no unwindng stack for coroutines
Min ho Kimc4cacc82019-07-31 08:16:13 +10001031 for "until" command if target breakpoint is not reached
Andrew Svetlov4f4ef0a2018-01-29 16:17:45 +02001032
1033 >>> import asyncio
1034
1035 >>> async def test_coro():
1036 ... print(0)
1037 ... await asyncio.sleep(0)
1038 ... print(1)
1039 ... await asyncio.sleep(0)
1040 ... print(2)
1041 ... await asyncio.sleep(0)
1042 ... print(3)
1043
1044 >>> async def test_main():
1045 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1046 ... await test_coro()
1047
1048 >>> def test_function():
1049 ... loop = asyncio.new_event_loop()
1050 ... loop.run_until_complete(test_main())
1051 ... loop.close()
Brett Cannon8425de42018-06-01 20:34:09 -07001052 ... asyncio.set_event_loop_policy(None)
Andrew Svetlov4f4ef0a2018-01-29 16:17:45 +02001053 ... print("finished")
1054
1055 >>> with PdbTestInput(['step',
1056 ... 'until 8',
1057 ... 'continue']):
1058 ... test_function()
1059 > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[2]>(3)test_main()
1060 -> await test_coro()
1061 (Pdb) step
1062 --Call--
1063 > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(1)test_coro()
1064 -> async def test_coro():
1065 (Pdb) until 8
1066 0
1067 1
1068 2
1069 > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(8)test_coro()
1070 -> print(3)
1071 (Pdb) continue
1072 3
1073 finished
1074 """
1075
Guido van Rossum8820c232013-11-21 11:30:06 -08001076def test_pdb_next_command_in_generator_for_loop():
Martin Panter46f50722016-05-26 05:35:26 +00001077 """The next command on returning from a generator controlled by a for loop.
Guido van Rossum8820c232013-11-21 11:30:06 -08001078
1079 >>> def test_gen():
1080 ... yield 0
1081 ... return 1
1082
1083 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001084 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Guido van Rossum8820c232013-11-21 11:30:06 -08001085 ... for i in test_gen():
1086 ... print('value', i)
1087 ... x = 123
1088
1089 >>> with PdbTestInput(['break test_gen',
1090 ... 'continue',
1091 ... 'next',
1092 ... 'next',
1093 ... 'next',
1094 ... 'continue']):
1095 ... test_function()
1096 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function()
1097 -> for i in test_gen():
1098 (Pdb) break test_gen
1099 Breakpoint 6 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1
1100 (Pdb) continue
1101 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(2)test_gen()
1102 -> yield 0
1103 (Pdb) next
1104 value 0
1105 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(3)test_gen()
1106 -> return 1
1107 (Pdb) next
1108 Internal StopIteration: 1
1109 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function()
1110 -> for i in test_gen():
1111 (Pdb) next
1112 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(5)test_function()
1113 -> x = 123
1114 (Pdb) continue
1115 """
1116
1117def test_pdb_next_command_subiterator():
1118 """The next command in a generator with a subiterator.
1119
1120 >>> def test_subgenerator():
1121 ... yield 0
1122 ... return 1
1123
1124 >>> def test_gen():
1125 ... x = yield from test_subgenerator()
1126 ... return x
1127
1128 >>> def test_function():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001129 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
Guido van Rossum8820c232013-11-21 11:30:06 -08001130 ... for i in test_gen():
1131 ... print('value', i)
1132 ... x = 123
1133
1134 >>> with PdbTestInput(['step',
1135 ... 'step',
1136 ... 'next',
1137 ... 'next',
1138 ... 'next',
1139 ... 'continue']):
1140 ... test_function()
1141 > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function()
1142 -> for i in test_gen():
1143 (Pdb) step
1144 --Call--
1145 > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(1)test_gen()
1146 -> def test_gen():
1147 (Pdb) step
1148 > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(2)test_gen()
1149 -> x = yield from test_subgenerator()
1150 (Pdb) next
1151 value 0
1152 > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(3)test_gen()
1153 -> return x
1154 (Pdb) next
1155 Internal StopIteration: 1
1156 > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function()
1157 -> for i in test_gen():
1158 (Pdb) next
1159 > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(5)test_function()
1160 -> x = 123
1161 (Pdb) continue
1162 """
1163
Xavier de Gaye10e54ae2016-10-12 20:13:24 +02001164def test_pdb_issue_20766():
1165 """Test for reference leaks when the SIGINT handler is set.
1166
1167 >>> def test_function():
1168 ... i = 1
1169 ... while i <= 2:
1170 ... sess = pdb.Pdb()
1171 ... sess.set_trace(sys._getframe())
1172 ... print('pdb %d: %s' % (i, sess._previous_sigint_handler))
1173 ... i += 1
1174
1175 >>> with PdbTestInput(['continue',
1176 ... 'continue']):
1177 ... test_function()
1178 > <doctest test.test_pdb.test_pdb_issue_20766[0]>(6)test_function()
1179 -> print('pdb %d: %s' % (i, sess._previous_sigint_handler))
1180 (Pdb) continue
1181 pdb 1: <built-in function default_int_handler>
1182 > <doctest test.test_pdb.test_pdb_issue_20766[0]>(5)test_function()
1183 -> sess.set_trace(sys._getframe())
1184 (Pdb) continue
1185 pdb 2: <built-in function default_int_handler>
1186 """
Georg Brandl46b9afc2010-07-30 09:14:20 +00001187
Georg Brandl6cccb862010-07-30 14:16:43 +00001188
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001189class PdbTestCase(unittest.TestCase):
1190 def tearDown(self):
1191 support.unlink(support.TESTFN)
1192
1193 def _run_pdb(self, pdb_args, commands):
1194 self.addCleanup(support.rmtree, '__pycache__')
1195 cmd = [sys.executable, '-m', 'pdb'] + pdb_args
1196 with subprocess.Popen(
1197 cmd,
1198 stdout=subprocess.PIPE,
1199 stdin=subprocess.PIPE,
1200 stderr=subprocess.STDOUT,
1201 ) as proc:
1202 stdout, stderr = proc.communicate(str.encode(commands))
1203 stdout = stdout and bytes.decode(stdout)
1204 stderr = stderr and bytes.decode(stderr)
1205 return stdout, stderr
1206
1207 def run_pdb_script(self, script, commands):
Senthil Kumaran42d70812012-05-01 10:07:49 +08001208 """Run 'script' lines with pdb and the pdb 'commands'."""
1209 filename = 'main.py'
1210 with open(filename, 'w') as f:
1211 f.write(textwrap.dedent(script))
Georg Brandl4bde9ca2012-05-01 09:21:16 +02001212 self.addCleanup(support.unlink, filename)
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001213 return self._run_pdb([filename], commands)
1214
1215 def run_pdb_module(self, script, commands):
1216 """Runs the script code as part of a module"""
1217 self.module_name = 't_main'
1218 support.rmtree(self.module_name)
1219 main_file = self.module_name + '/__main__.py'
1220 init_file = self.module_name + '/__init__.py'
1221 os.mkdir(self.module_name)
1222 with open(init_file, 'w') as f:
1223 pass
1224 with open(main_file, 'w') as f:
1225 f.write(textwrap.dedent(script))
1226 self.addCleanup(support.rmtree, self.module_name)
1227 return self._run_pdb(['-m', self.module_name], commands)
Senthil Kumaran42d70812012-05-01 10:07:49 +08001228
Georg Brandl6e220552013-10-13 20:51:47 +02001229 def _assert_find_function(self, file_content, func_name, expected):
Serhiy Storchaka19fcffa2020-06-21 11:07:50 +03001230 with open(support.TESTFN, 'wb') as f:
Georg Brandl6e220552013-10-13 20:51:47 +02001231 f.write(file_content)
1232
1233 expected = None if not expected else (
1234 expected[0], support.TESTFN, expected[1])
1235 self.assertEqual(
1236 expected, pdb.find_function(func_name, support.TESTFN))
1237
1238 def test_find_function_empty_file(self):
Serhiy Storchaka19fcffa2020-06-21 11:07:50 +03001239 self._assert_find_function(b'', 'foo', None)
Georg Brandl6e220552013-10-13 20:51:47 +02001240
1241 def test_find_function_found(self):
1242 self._assert_find_function(
1243 """\
Serhiy Storchaka19fcffa2020-06-21 11:07:50 +03001244def foo():
1245 pass
Georg Brandl6e220552013-10-13 20:51:47 +02001246
Serhiy Storchaka19fcffa2020-06-21 11:07:50 +03001247def bœr():
1248 pass
Georg Brandl6e220552013-10-13 20:51:47 +02001249
Serhiy Storchaka19fcffa2020-06-21 11:07:50 +03001250def quux():
1251 pass
1252""".encode(),
1253 'bœr',
1254 ('bœr', 4),
1255 )
1256
1257 def test_find_function_found_with_encoding_cookie(self):
1258 self._assert_find_function(
1259 """\
1260# coding: iso-8859-15
1261def foo():
1262 pass
1263
1264def bœr():
1265 pass
1266
1267def quux():
1268 pass
1269""".encode('iso-8859-15'),
1270 'bœr',
1271 ('bœr', 5),
1272 )
1273
1274 def test_find_function_found_with_bom(self):
1275 self._assert_find_function(
1276 codecs.BOM_UTF8 + """\
1277def bœr():
1278 pass
1279""".encode(),
1280 'bœr',
1281 ('bœr', 1),
Georg Brandl6e220552013-10-13 20:51:47 +02001282 )
1283
Georg Brandl6cccb862010-07-30 14:16:43 +00001284 def test_issue7964(self):
1285 # open the file as binary so we can force \r\n newline
1286 with open(support.TESTFN, 'wb') as f:
1287 f.write(b'print("testing my pdb")\r\n')
1288 cmd = [sys.executable, '-m', 'pdb', support.TESTFN]
1289 proc = subprocess.Popen(cmd,
1290 stdout=subprocess.PIPE,
1291 stdin=subprocess.PIPE,
1292 stderr=subprocess.STDOUT,
1293 )
Brian Curtin994ad6c2010-11-05 15:38:47 +00001294 self.addCleanup(proc.stdout.close)
Georg Brandl6cccb862010-07-30 14:16:43 +00001295 stdout, stderr = proc.communicate(b'quit\n')
1296 self.assertNotIn(b'SyntaxError', stdout,
1297 "Got a syntax error running test script under PDB")
1298
Senthil Kumaran42d70812012-05-01 10:07:49 +08001299 def test_issue13183(self):
1300 script = """
1301 from bar import bar
1302
1303 def foo():
1304 bar()
1305
1306 def nope():
1307 pass
1308
1309 def foobar():
1310 foo()
1311 nope()
1312
1313 foobar()
1314 """
1315 commands = """
1316 from bar import bar
1317 break bar
1318 continue
1319 step
1320 step
1321 quit
1322 """
1323 bar = """
1324 def bar():
Senthil Kumarancb172042012-05-02 08:00:22 +08001325 pass
Senthil Kumaran42d70812012-05-01 10:07:49 +08001326 """
1327 with open('bar.py', 'w') as f:
1328 f.write(textwrap.dedent(bar))
Georg Brandl4bde9ca2012-05-01 09:21:16 +02001329 self.addCleanup(support.unlink, 'bar.py')
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001330 stdout, stderr = self.run_pdb_script(script, commands)
Georg Brandl4bde9ca2012-05-01 09:21:16 +02001331 self.assertTrue(
1332 any('main.py(5)foo()->None' in l for l in stdout.splitlines()),
1333 'Fail to step into the caller after a return')
Senthil Kumaran42d70812012-05-01 10:07:49 +08001334
Daniel Hahler9139f922019-04-01 23:59:50 +02001335 def test_issue13120(self):
1336 # Invoking "continue" on a non-main thread triggered an exception
1337 # inside signal.signal.
Andrew Svetlov539ee5d2012-12-04 21:08:28 +02001338
1339 with open(support.TESTFN, 'wb') as f:
1340 f.write(textwrap.dedent("""
1341 import threading
1342 import pdb
1343
1344 def start_pdb():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001345 pdb.Pdb(readrc=False).set_trace()
Andrew Svetlov539ee5d2012-12-04 21:08:28 +02001346 x = 1
1347 y = 1
1348
1349 t = threading.Thread(target=start_pdb)
1350 t.start()""").encode('ascii'))
1351 cmd = [sys.executable, '-u', support.TESTFN]
1352 proc = subprocess.Popen(cmd,
1353 stdout=subprocess.PIPE,
1354 stdin=subprocess.PIPE,
1355 stderr=subprocess.STDOUT,
1356 )
1357 self.addCleanup(proc.stdout.close)
1358 stdout, stderr = proc.communicate(b'cont\n')
1359 self.assertNotIn('Error', stdout.decode(),
1360 "Got an error running test script under PDB")
1361
Daniel Hahler8d64bfa2019-09-09 12:45:58 +02001362 def test_issue36250(self):
1363
1364 with open(support.TESTFN, 'wb') as f:
1365 f.write(textwrap.dedent("""
1366 import threading
1367 import pdb
1368
1369 evt = threading.Event()
1370
1371 def start_pdb():
1372 evt.wait()
1373 pdb.Pdb(readrc=False).set_trace()
1374
1375 t = threading.Thread(target=start_pdb)
1376 t.start()
1377 pdb.Pdb(readrc=False).set_trace()
1378 evt.set()
1379 t.join()""").encode('ascii'))
1380 cmd = [sys.executable, '-u', support.TESTFN]
1381 proc = subprocess.Popen(cmd,
1382 stdout=subprocess.PIPE,
1383 stdin=subprocess.PIPE,
1384 stderr=subprocess.STDOUT,
1385 )
1386 self.addCleanup(proc.stdout.close)
1387 stdout, stderr = proc.communicate(b'cont\ncont\n')
1388 self.assertNotIn('Error', stdout.decode(),
1389 "Got an error running test script under PDB")
1390
Terry Jan Reedyca3f4352015-09-05 19:13:26 -04001391 def test_issue16180(self):
1392 # A syntax error in the debuggee.
1393 script = "def f: pass\n"
1394 commands = ''
1395 expected = "SyntaxError:"
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001396 stdout, stderr = self.run_pdb_script(script, commands)
Terry Jan Reedyca3f4352015-09-05 19:13:26 -04001397 self.assertIn(expected, stdout,
1398 '\n\nExpected:\n{}\nGot:\n{}\n'
1399 'Fail to handle a syntax error in the debuggee.'
1400 .format(expected, stdout))
1401
1402
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001403 def test_readrc_kwarg(self):
Victor Stinner11ea0442016-09-09 22:56:54 -07001404 script = textwrap.dedent("""
1405 import pdb; pdb.Pdb(readrc=False).set_trace()
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001406
Victor Stinner11ea0442016-09-09 22:56:54 -07001407 print('hello')
1408 """)
Victor Stinner11ea0442016-09-09 22:56:54 -07001409
Victor Stinnerbc626262016-09-09 23:22:09 -07001410 save_home = os.environ.pop('HOME', None)
1411 try:
1412 with support.temp_cwd():
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001413 with open('.pdbrc', 'w') as f:
1414 f.write("invalid\n")
1415
1416 with open('main.py', 'w') as f:
1417 f.write(script)
1418
1419 cmd = [sys.executable, 'main.py']
1420 proc = subprocess.Popen(
1421 cmd,
1422 stdout=subprocess.PIPE,
1423 stdin=subprocess.PIPE,
1424 stderr=subprocess.PIPE,
1425 )
Victor Stinnerbc626262016-09-09 23:22:09 -07001426 with proc:
1427 stdout, stderr = proc.communicate(b'q\n')
1428 self.assertNotIn("NameError: name 'invalid' is not defined",
1429 stdout.decode())
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001430
1431 finally:
Victor Stinner11ea0442016-09-09 22:56:54 -07001432 if save_home is not None:
1433 os.environ['HOME'] = save_home
Łukasz Langa2eb6eca2016-09-09 22:21:17 -07001434
Timothy Hopper7ea9a852019-08-02 18:20:14 -04001435 def test_readrc_homedir(self):
1436 save_home = os.environ.pop("HOME", None)
1437 with support.temp_dir() as temp_dir, patch("os.path.expanduser"):
1438 rc_path = os.path.join(temp_dir, ".pdbrc")
1439 os.path.expanduser.return_value = rc_path
1440 try:
1441 with open(rc_path, "w") as f:
1442 f.write("invalid")
1443 self.assertEqual(pdb.Pdb().rcLines[0], "invalid")
1444 finally:
1445 if save_home is not None:
1446 os.environ["HOME"] = save_home
1447
Barry Warsaw35425d62017-09-22 12:29:42 -04001448 def test_header(self):
1449 stdout = StringIO()
1450 header = 'Nobody expects... blah, blah, blah'
1451 with ExitStack() as resources:
1452 resources.enter_context(patch('sys.stdout', stdout))
1453 resources.enter_context(patch.object(pdb.Pdb, 'set_trace'))
1454 pdb.set_trace(header=header)
1455 self.assertEqual(stdout.getvalue(), header + '\n')
1456
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001457 def test_run_module(self):
1458 script = """print("SUCCESS")"""
1459 commands = """
1460 continue
1461 quit
1462 """
1463 stdout, stderr = self.run_pdb_module(script, commands)
1464 self.assertTrue(any("SUCCESS" in l for l in stdout.splitlines()), stdout)
1465
1466 def test_module_is_run_as_main(self):
1467 script = """
1468 if __name__ == '__main__':
1469 print("SUCCESS")
1470 """
1471 commands = """
1472 continue
1473 quit
1474 """
1475 stdout, stderr = self.run_pdb_module(script, commands)
1476 self.assertTrue(any("SUCCESS" in l for l in stdout.splitlines()), stdout)
1477
1478 def test_breakpoint(self):
1479 script = """
1480 if __name__ == '__main__':
1481 pass
1482 print("SUCCESS")
1483 pass
1484 """
1485 commands = """
1486 b 3
1487 quit
1488 """
1489 stdout, stderr = self.run_pdb_module(script, commands)
1490 self.assertTrue(any("Breakpoint 1 at" in l for l in stdout.splitlines()), stdout)
1491 self.assertTrue(all("SUCCESS" not in l for l in stdout.splitlines()), stdout)
1492
1493 def test_run_pdb_with_pdb(self):
1494 commands = """
1495 c
1496 quit
1497 """
1498 stdout, stderr = self._run_pdb(["-m", "pdb"], commands)
Mario Corcherofcf8b4c2018-01-28 04:58:47 +00001499 self.assertIn(
1500 pdb._usage,
1501 stdout.replace('\r', '') # remove \r for windows
1502 )
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001503
1504 def test_module_without_a_main(self):
1505 module_name = 't_main'
1506 support.rmtree(module_name)
1507 init_file = module_name + '/__init__.py'
1508 os.mkdir(module_name)
1509 with open(init_file, 'w') as f:
1510 pass
1511 self.addCleanup(support.rmtree, module_name)
1512 stdout, stderr = self._run_pdb(['-m', module_name], "")
1513 self.assertIn("ImportError: No module named t_main.__main__",
1514 stdout.splitlines())
1515
1516 def test_blocks_at_first_code_line(self):
1517 script = """
1518 #This is a comment, on line 2
1519
1520 print("SUCCESS")
1521 """
1522 commands = """
1523 quit
1524 """
1525 stdout, stderr = self.run_pdb_module(script, commands)
1526 self.assertTrue(any("__main__.py(4)<module>()"
1527 in l for l in stdout.splitlines()), stdout)
1528
1529 def test_relative_imports(self):
1530 self.module_name = 't_main'
1531 support.rmtree(self.module_name)
1532 main_file = self.module_name + '/__main__.py'
1533 init_file = self.module_name + '/__init__.py'
1534 module_file = self.module_name + '/module.py'
1535 self.addCleanup(support.rmtree, self.module_name)
1536 os.mkdir(self.module_name)
1537 with open(init_file, 'w') as f:
1538 f.write(textwrap.dedent("""
1539 top_var = "VAR from top"
1540 """))
1541 with open(main_file, 'w') as f:
1542 f.write(textwrap.dedent("""
1543 from . import top_var
1544 from .module import var
1545 from . import module
1546 pass # We'll stop here and print the vars
1547 """))
1548 with open(module_file, 'w') as f:
1549 f.write(textwrap.dedent("""
1550 var = "VAR from module"
1551 var2 = "second var"
1552 """))
1553 commands = """
1554 b 5
1555 c
1556 p top_var
1557 p var
1558 p module.var2
1559 quit
1560 """
1561 stdout, _ = self._run_pdb(['-m', self.module_name], commands)
Mario Corchero38bfa842018-02-03 06:40:11 +00001562 self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout)
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001563 self.assertTrue(any("VAR from top" in l for l in stdout.splitlines()))
1564 self.assertTrue(any("second var" in l for l in stdout.splitlines()))
Georg Brandl6cccb862010-07-30 14:16:43 +00001565
Mario Corchero38bfa842018-02-03 06:40:11 +00001566 def test_relative_imports_on_plain_module(self):
1567 # Validates running a plain module. See bpo32691
1568 self.module_name = 't_main'
1569 support.rmtree(self.module_name)
1570 main_file = self.module_name + '/runme.py'
1571 init_file = self.module_name + '/__init__.py'
1572 module_file = self.module_name + '/module.py'
1573 self.addCleanup(support.rmtree, self.module_name)
1574 os.mkdir(self.module_name)
1575 with open(init_file, 'w') as f:
1576 f.write(textwrap.dedent("""
1577 top_var = "VAR from top"
1578 """))
1579 with open(main_file, 'w') as f:
1580 f.write(textwrap.dedent("""
1581 from . import module
1582 pass # We'll stop here and print the vars
1583 """))
1584 with open(module_file, 'w') as f:
1585 f.write(textwrap.dedent("""
1586 var = "VAR from module"
1587 """))
1588 commands = """
1589 b 3
1590 c
1591 p module.var
1592 quit
1593 """
1594 stdout, _ = self._run_pdb(['-m', self.module_name + '.runme'], commands)
1595 self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout)
1596
Daniel Hahler3e936432019-03-12 04:29:04 +01001597 def test_errors_in_command(self):
1598 commands = "\n".join([
1599 'print(',
1600 'debug print(',
1601 'debug doesnotexist',
1602 'c',
1603 ])
1604 stdout, _ = self.run_pdb_script('', commands + '\n')
1605
Daniel Hahler43277052019-02-15 21:52:53 +01001606 self.assertEqual(stdout.splitlines()[1:], [
1607 '(Pdb) *** SyntaxError: unexpected EOF while parsing',
Daniel Hahler3e936432019-03-12 04:29:04 +01001608
1609 '(Pdb) ENTERING RECURSIVE DEBUGGER',
1610 '*** SyntaxError: unexpected EOF while parsing',
1611 'LEAVING RECURSIVE DEBUGGER',
1612
1613 '(Pdb) ENTERING RECURSIVE DEBUGGER',
1614 '> <string>(1)<module>()',
1615 "((Pdb)) *** NameError: name 'doesnotexist' is not defined",
1616 'LEAVING RECURSIVE DEBUGGER',
Daniel Hahler43277052019-02-15 21:52:53 +01001617 '(Pdb) ',
1618 ])
Georg Brandl6cccb862010-07-30 14:16:43 +00001619
Andrew Svetlovf0efea02013-03-18 10:09:50 -07001620def load_tests(*args):
Georg Brandl243ad662009-05-05 09:00:19 +00001621 from test import test_pdb
Mario Corchero9f1e5f12018-01-06 07:53:05 +00001622 suites = [
1623 unittest.makeSuite(PdbTestCase),
1624 doctest.DocTestSuite(test_pdb)
1625 ]
Andrew Svetlovf0efea02013-03-18 10:09:50 -07001626 return unittest.TestSuite(suites)
Georg Brandl243ad662009-05-05 09:00:19 +00001627
1628
1629if __name__ == '__main__':
Andrew Svetlovf0efea02013-03-18 10:09:50 -07001630 unittest.main()