Skip to content

Commit 9ee1bf9

Browse files
authored
bpo-32650: Add an asyncgen pdb test (#5406)
1 parent 997478e commit 9ee1bf9

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

‎Lib/test/test_pdb.py‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,66 @@ def test_pdb_next_command_for_coroutine():
782782
finished
783783
"""
784784

785+
def test_pdb_next_command_for_asyncgen():
786+
"""Testing skip unwindng stack on yield for coroutines for "next" command
787+
788+
>>> import asyncio
789+
790+
>>> async def agen():
791+
... yield 1
792+
... await asyncio.sleep(0)
793+
... yield 2
794+
795+
>>> async def test_coro():
796+
... async for x in agen():
797+
... print(x)
798+
799+
>>> async def test_main():
800+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
801+
... await test_coro()
802+
803+
>>> def test_function():
804+
... loop = asyncio.new_event_loop()
805+
... loop.run_until_complete(test_main())
806+
... loop.close()
807+
... print("finished")
808+
809+
>>> with PdbTestInput(['step',
810+
... 'step',
811+
... 'next',
812+
... 'next',
813+
... 'step',
814+
... 'next',
815+
... 'continue']):
816+
... test_function()
817+
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[3]>(3)test_main()
818+
-> await test_coro()
819+
(Pdb) step
820+
--Call--
821+
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(1)test_coro()
822+
-> async def test_coro():
823+
(Pdb) step
824+
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro()
825+
-> async for x in agen():
826+
(Pdb) next
827+
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(3)test_coro()
828+
-> print(x)
829+
(Pdb) next
830+
1
831+
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro()
832+
-> async for x in agen():
833+
(Pdb) step
834+
--Call--
835+
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(2)agen()
836+
-> yield 1
837+
(Pdb) next
838+
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(3)agen()
839+
-> await asyncio.sleep(0)
840+
(Pdb) continue
841+
2
842+
finished
843+
"""
844+
785845
def test_pdb_return_command_for_generator():
786846
"""Testing no unwindng stack on yield for generators
787847
for "return" command

0 commit comments

Comments
 (0)