Skip to content

Commit 44eafd6

Browse files
authored
gh-121008: Fix idlelib.run tests (#121046)
When testing IDLE, don't create a Tk to avoid side effects such as installing a PyOS_InputHook hook.
1 parent c878767 commit 44eafd6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Lib/idlelib/run.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,20 @@ def capture_warnings(capture):
9191
_warnings_showwarning = None
9292

9393
capture_warnings(True)
94-
tcl = tkinter.Tcl()
9594

96-
def handle_tk_events(tcl=tcl):
97-
"""Process any tk events that are ready to be dispatched if tkinter
98-
has been imported, a tcl interpreter has been created and tk has been
99-
loaded."""
100-
tcl.eval("update")
95+
if idlelib.testing:
96+
# gh-121008: When testing IDLE, don't create a Tk object to avoid side
97+
# effects such as installing a PyOS_InputHook hook.
98+
def handle_tk_events():
99+
pass
100+
else:
101+
tcl = tkinter.Tcl()
102+
103+
def handle_tk_events(tcl=tcl):
104+
"""Process any tk events that are ready to be dispatched if tkinter
105+
has been imported, a tcl interpreter has been created and tk has been
106+
loaded."""
107+
tcl.eval("update")
101108

102109
# Thread shared globals: Establish a queue between a subthread (which handles
103110
# the socket) and the main thread (which runs user code), plus global

0 commit comments

Comments
 (0)