[3.12] gh-114275: Skip doctests that use asyncio in test_pdb for WASI builds (GH-114309) (#114439)

gh-114275: Skip doctests that use `asyncio` in `test_pdb` for WASI builds (GH-114309)
(cherry picked from commit efb81a60f5)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2024-01-22 18:02:23 +01:00 committed by GitHub
parent f9979212f8
commit 4890ac136b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,9 @@ from test.support.import_helper import import_module
from test.support.pty_helper import run_pty, FakeInput from test.support.pty_helper import run_pty, FakeInput
from unittest.mock import patch from unittest.mock import patch
# gh-114275: WASI fails to run asyncio tests, similar skip than test_asyncio.
SKIP_ASYNCIO_TESTS = (not support.has_socket_support)
class PdbTestInput(object): class PdbTestInput(object):
"""Context manager that makes testing Pdb in doctests easier.""" """Context manager that makes testing Pdb in doctests easier."""
@ -1180,122 +1183,123 @@ def test_pdb_next_command_for_generator():
finished finished
""" """
def test_pdb_next_command_for_coroutine(): if not SKIP_ASYNCIO_TESTS:
"""Testing skip unwindng stack on yield for coroutines for "next" command def test_pdb_next_command_for_coroutine():
"""Testing skip unwindng stack on yield for coroutines for "next" command
>>> import asyncio >>> import asyncio
>>> async def test_coro(): >>> async def test_coro():
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... await asyncio.sleep(0) ... await asyncio.sleep(0)
>>> async def test_main(): >>> async def test_main():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... await test_coro() ... await test_coro()
>>> def test_function(): >>> def test_function():
... loop = asyncio.new_event_loop() ... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main()) ... loop.run_until_complete(test_main())
... loop.close() ... loop.close()
... asyncio.set_event_loop_policy(None) ... asyncio.set_event_loop_policy(None)
... print("finished") ... print("finished")
>>> with PdbTestInput(['step', >>> with PdbTestInput(['step',
... 'step', ... 'step',
... 'next', ... 'next',
... 'next', ... 'next',
... 'next', ... 'next',
... 'step', ... 'step',
... 'continue']): ... 'continue']):
... test_function() ... test_function()
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main() > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()
-> await test_coro() -> await test_coro()
(Pdb) step (Pdb) step
--Call-- --Call--
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(1)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(1)test_coro()
-> async def test_coro(): -> async def test_coro():
(Pdb) step (Pdb) step
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(2)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(2)test_coro()
-> await asyncio.sleep(0) -> await asyncio.sleep(0)
(Pdb) next (Pdb) next
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(3)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(3)test_coro()
-> await asyncio.sleep(0) -> await asyncio.sleep(0)
(Pdb) next (Pdb) next
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(4)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(4)test_coro()
-> await asyncio.sleep(0) -> await asyncio.sleep(0)
(Pdb) next (Pdb) next
Internal StopIteration Internal StopIteration
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main() > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()
-> await test_coro() -> await test_coro()
(Pdb) step (Pdb) step
--Return-- --Return--
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()->None > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()->None
-> await test_coro() -> await test_coro()
(Pdb) continue (Pdb) continue
finished finished
""" """
def test_pdb_next_command_for_asyncgen(): def test_pdb_next_command_for_asyncgen():
"""Testing skip unwindng stack on yield for coroutines for "next" command """Testing skip unwindng stack on yield for coroutines for "next" command
>>> import asyncio >>> import asyncio
>>> async def agen(): >>> async def agen():
... yield 1 ... yield 1
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... yield 2 ... yield 2
>>> async def test_coro(): >>> async def test_coro():
... async for x in agen(): ... async for x in agen():
... print(x) ... print(x)
>>> async def test_main(): >>> async def test_main():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... await test_coro() ... await test_coro()
>>> def test_function(): >>> def test_function():
... loop = asyncio.new_event_loop() ... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main()) ... loop.run_until_complete(test_main())
... loop.close() ... loop.close()
... asyncio.set_event_loop_policy(None) ... asyncio.set_event_loop_policy(None)
... print("finished") ... print("finished")
>>> with PdbTestInput(['step', >>> with PdbTestInput(['step',
... 'step', ... 'step',
... 'next', ... 'next',
... 'next', ... 'next',
... 'step', ... 'step',
... 'next', ... 'next',
... 'continue']): ... 'continue']):
... test_function() ... test_function()
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[3]>(3)test_main() > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[3]>(3)test_main()
-> await test_coro() -> await test_coro()
(Pdb) step (Pdb) step
--Call-- --Call--
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(1)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(1)test_coro()
-> async def test_coro(): -> async def test_coro():
(Pdb) step (Pdb) step
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro()
-> async for x in agen(): -> async for x in agen():
(Pdb) next (Pdb) next
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(3)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(3)test_coro()
-> print(x) -> print(x)
(Pdb) next (Pdb) next
1 1
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro() > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro()
-> async for x in agen(): -> async for x in agen():
(Pdb) step (Pdb) step
--Call-- --Call--
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(2)agen() > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(2)agen()
-> yield 1 -> yield 1
(Pdb) next (Pdb) next
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(3)agen() > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(3)agen()
-> await asyncio.sleep(0) -> await asyncio.sleep(0)
(Pdb) continue (Pdb) continue
2 2
finished finished
""" """
def test_pdb_return_command_for_generator(): def test_pdb_return_command_for_generator():
"""Testing no unwindng stack on yield for generators """Testing no unwindng stack on yield for generators
@ -1352,47 +1356,48 @@ def test_pdb_return_command_for_generator():
finished finished
""" """
def test_pdb_return_command_for_coroutine(): if not SKIP_ASYNCIO_TESTS:
"""Testing no unwindng stack on yield for coroutines for "return" command def test_pdb_return_command_for_coroutine():
"""Testing no unwindng stack on yield for coroutines for "return" command
>>> import asyncio >>> import asyncio
>>> async def test_coro(): >>> async def test_coro():
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... await asyncio.sleep(0) ... await asyncio.sleep(0)
>>> async def test_main(): >>> async def test_main():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... await test_coro() ... await test_coro()
>>> def test_function(): >>> def test_function():
... loop = asyncio.new_event_loop() ... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main()) ... loop.run_until_complete(test_main())
... loop.close() ... loop.close()
... asyncio.set_event_loop_policy(None) ... asyncio.set_event_loop_policy(None)
... print("finished") ... print("finished")
>>> with PdbTestInput(['step', >>> with PdbTestInput(['step',
... 'step', ... 'step',
... 'next', ... 'next',
... 'continue']): ... 'continue']):
... test_function() ... test_function()
> <doctest test.test_pdb.test_pdb_return_command_for_coroutine[2]>(3)test_main() > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[2]>(3)test_main()
-> await test_coro() -> await test_coro()
(Pdb) step (Pdb) step
--Call-- --Call--
> <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(1)test_coro() > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(1)test_coro()
-> async def test_coro(): -> async def test_coro():
(Pdb) step (Pdb) step
> <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(2)test_coro() > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(2)test_coro()
-> await asyncio.sleep(0) -> await asyncio.sleep(0)
(Pdb) next (Pdb) next
> <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(3)test_coro() > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(3)test_coro()
-> await asyncio.sleep(0) -> await asyncio.sleep(0)
(Pdb) continue (Pdb) continue
finished finished
""" """
def test_pdb_until_command_for_generator(): def test_pdb_until_command_for_generator():
"""Testing no unwindng stack on yield for generators """Testing no unwindng stack on yield for generators
@ -1438,52 +1443,53 @@ def test_pdb_until_command_for_generator():
finished finished
""" """
def test_pdb_until_command_for_coroutine(): if not SKIP_ASYNCIO_TESTS:
"""Testing no unwindng stack for coroutines def test_pdb_until_command_for_coroutine():
for "until" command if target breakpoint is not reached """Testing no unwindng stack for coroutines
for "until" command if target breakpoint is not reached
>>> import asyncio >>> import asyncio
>>> async def test_coro(): >>> async def test_coro():
... print(0) ... print(0)
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... print(1) ... print(1)
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... print(2) ... print(2)
... await asyncio.sleep(0) ... await asyncio.sleep(0)
... print(3) ... print(3)
>>> async def test_main(): >>> async def test_main():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... await test_coro() ... await test_coro()
>>> def test_function(): >>> def test_function():
... loop = asyncio.new_event_loop() ... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main()) ... loop.run_until_complete(test_main())
... loop.close() ... loop.close()
... asyncio.set_event_loop_policy(None) ... asyncio.set_event_loop_policy(None)
... print("finished") ... print("finished")
>>> with PdbTestInput(['step', >>> with PdbTestInput(['step',
... 'until 8', ... 'until 8',
... 'continue']): ... 'continue']):
... test_function() ... test_function()
> <doctest test.test_pdb.test_pdb_until_command_for_coroutine[2]>(3)test_main() > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[2]>(3)test_main()
-> await test_coro() -> await test_coro()
(Pdb) step (Pdb) step
--Call-- --Call--
> <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(1)test_coro() > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(1)test_coro()
-> async def test_coro(): -> async def test_coro():
(Pdb) until 8 (Pdb) until 8
0 0
1 1
2 2
> <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(8)test_coro() > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(8)test_coro()
-> print(3) -> print(3)
(Pdb) continue (Pdb) continue
3 3
finished finished
""" """
def test_pdb_next_command_in_generator_for_loop(): def test_pdb_next_command_in_generator_for_loop():
"""The next command on returning from a generator controlled by a for loop. """The next command on returning from a generator controlled by a for loop.