Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-121468: Ensure PDB cleans up event loop policies after using asyncio. #131388

Merged
merged 3 commits into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import zipapp
import zipfile

from asyncio.events import _set_event_loop_policy
from contextlib import ExitStack, redirect_stdout
from io import StringIO
from test import support
Expand Down Expand Up @@ -2154,7 +2155,7 @@ def test_pdb_asynctask():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()

>>> def test_function():
... asyncio.run(test())
... asyncio.run(test(), loop_factory=asyncio.EventLoop)

>>> with PdbTestInput([ # doctest: +ELLIPSIS
... '$_asynctask',
Expand Down Expand Up @@ -4670,13 +4671,33 @@ def func():

def load_tests(loader, tests, pattern):
from test import test_pdb

def setUpPdbBackend(backend):
def setUp(test):
import pdb
pdb.set_default_backend(backend)
return setUp
tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('monitoring')))
tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('settrace')))

def tearDown(test):
# Ensure that asyncio state has been cleared at the end of the test.
# This prevents a "test altered the execution environment" warning if
# asyncio features are used.
_set_event_loop_policy(None)

tests.addTest(
doctest.DocTestSuite(
test_pdb,
setUp=setUpPdbBackend('monitoring'),
tearDown=tearDown,
)
)
tests.addTest(
doctest.DocTestSuite(
test_pdb,
setUp=setUpPdbBackend('settrace'),
tearDown=tearDown,
)
)
return tests


Expand Down
Loading