|
13 | 13 | import zipapp |
14 | 14 | import zipfile |
15 | 15 |
|
| 16 | +from asyncio.events import _set_event_loop_policy |
16 | 17 | from contextlib import ExitStack, redirect_stdout |
17 | 18 | from io import StringIO |
18 | 19 | from test import support |
@@ -2154,7 +2155,7 @@ def test_pdb_asynctask(): |
2154 | 2155 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
2155 | 2156 |
|
2156 | 2157 | >>> def test_function(): |
2157 | | - ... asyncio.run(test()) |
| 2158 | + ... asyncio.run(test(), loop_factory=asyncio.EventLoop) |
2158 | 2159 |
|
2159 | 2160 | >>> with PdbTestInput([ # doctest: +ELLIPSIS |
2160 | 2161 | ... '$_asynctask', |
@@ -4670,13 +4671,33 @@ def func(): |
4670 | 4671 |
|
4671 | 4672 | def load_tests(loader, tests, pattern): |
4672 | 4673 | from test import test_pdb |
| 4674 | + |
4673 | 4675 | def setUpPdbBackend(backend): |
4674 | 4676 | def setUp(test): |
4675 | 4677 | import pdb |
4676 | 4678 | pdb.set_default_backend(backend) |
4677 | 4679 | return setUp |
4678 | | - tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('monitoring'))) |
4679 | | - tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('settrace'))) |
| 4680 | + |
| 4681 | + def tearDown(test): |
| 4682 | + # Ensure that asyncio state has been cleared at the end of the test. |
| 4683 | + # This prevents a "test altered the execution environment" warning if |
| 4684 | + # asyncio features are used. |
| 4685 | + _set_event_loop_policy(None) |
| 4686 | + |
| 4687 | + tests.addTest( |
| 4688 | + doctest.DocTestSuite( |
| 4689 | + test_pdb, |
| 4690 | + setUp=setUpPdbBackend('monitoring'), |
| 4691 | + tearDown=tearDown, |
| 4692 | + ) |
| 4693 | + ) |
| 4694 | + tests.addTest( |
| 4695 | + doctest.DocTestSuite( |
| 4696 | + test_pdb, |
| 4697 | + setUp=setUpPdbBackend('settrace'), |
| 4698 | + tearDown=tearDown, |
| 4699 | + ) |
| 4700 | + ) |
4680 | 4701 | return tests |
4681 | 4702 |
|
4682 | 4703 |
|
|
0 commit comments