[3.13] gh-121008: Fix idlelib.run tests (GH-121046) (#121049)

gh-121008: Fix idlelib.run tests (GH-121046)

When testing IDLE, don't create a Tk to avoid side effects such as
installing a PyOS_InputHook hook.
(cherry picked from commit 44eafd6688)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2024-06-26 16:08:31 +02:00 committed by GitHub
parent 7db14f1eba
commit bdcc738fec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 6 deletions

View File

@ -91,13 +91,20 @@ def capture_warnings(capture):
_warnings_showwarning = None
capture_warnings(True)
tcl = tkinter.Tcl()
def handle_tk_events(tcl=tcl):
"""Process any tk events that are ready to be dispatched if tkinter
has been imported, a tcl interpreter has been created and tk has been
loaded."""
tcl.eval("update")
if idlelib.testing:
# gh-121008: When testing IDLE, don't create a Tk object to avoid side
# effects such as installing a PyOS_InputHook hook.
def handle_tk_events():
pass
else:
tcl = tkinter.Tcl()
def handle_tk_events(tcl=tcl):
"""Process any tk events that are ready to be dispatched if tkinter
has been imported, a tcl interpreter has been created and tk has been
loaded."""
tcl.eval("update")
# Thread shared globals: Establish a queue between a subthread (which handles
# the socket) and the main thread (which runs user code), plus global