Skip to content

Commit 50c3c9c

Browse files
Add breakpoint tests
1 parent a3401e9 commit 50c3c9c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Lib/test/test_pdb.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,59 @@ def test_pdb_await_support():
22332233
(Pdb) continue
22342234
"""
22352235

2236+
def test_pdb_await_with_breakpoint():
2237+
"""Testing await support with breakpoints set in tasks
2238+
2239+
>>> reset_Breakpoint()
2240+
2241+
>>> import asyncio
2242+
2243+
>>> async def test():
2244+
... x = 2
2245+
... await asyncio.sleep(0)
2246+
... return 42
2247+
2248+
>>> async def main():
2249+
... import pdb;
2250+
... task = asyncio.create_task(test())
2251+
... await pdb.Pdb(nosigint=True, readrc=False).set_trace_async()
2252+
2253+
>>> def test_function():
2254+
... asyncio.run(main(), loop_factory=asyncio.EventLoop)
2255+
2256+
>>> with PdbTestInput([ # doctest: +ELLIPSIS
2257+
... 'b test',
2258+
... 'k = await task',
2259+
... 'n',
2260+
... 'p x',
2261+
... 'continue',
2262+
... 'p k',
2263+
... 'clear 1',
2264+
... 'continue',
2265+
... ]):
2266+
... test_function()
2267+
> <doctest test.test_pdb.test_pdb_await_with_breakpoint[3]>(4)main()
2268+
-> await pdb.Pdb(nosigint=True, readrc=False).set_trace_async()
2269+
(Pdb) b test
2270+
Breakpoint 1 at <doctest test.test_pdb.test_pdb_await_with_breakpoint[2]>:2
2271+
(Pdb) k = await task
2272+
> <doctest test.test_pdb.test_pdb_await_with_breakpoint[2]>(2)test()
2273+
-> x = 2
2274+
(Pdb) n
2275+
> <doctest test.test_pdb.test_pdb_await_with_breakpoint[2]>(3)test()
2276+
-> await asyncio.sleep(0)
2277+
(Pdb) p x
2278+
2
2279+
(Pdb) continue
2280+
> <doctest test.test_pdb.test_pdb_await_with_breakpoint[3]>(4)main()
2281+
-> await pdb.Pdb(nosigint=True, readrc=False).set_trace_async()
2282+
(Pdb) p k
2283+
42
2284+
(Pdb) clear 1
2285+
Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_await_with_breakpoint[2]>:2
2286+
(Pdb) continue
2287+
"""
2288+
22362289
def test_pdb_next_command_for_coroutine():
22372290
"""Testing skip unwinding stack on yield for coroutines for "next" command
22382291

0 commit comments

Comments
 (0)