]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-121008: Fix idlelib.run tests (GH-121046) (#121049)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 26 Jun 2024 14:08:31 +0000 (16:08 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Jun 2024 14:08:31 +0000 (14:08 +0000)
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 44eafd66882589d4f4eb569d70c49724da3e9291)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/idlelib/run.py

index 53e80a9b42801fb305d19b4fd4fa64dc7a6de52a..8974b52674fb8c8ea0d2f3280fbb240b34fdbd24 100644 (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