diff options
author | Victor Stinner <vstinner@python.org> | 2024-06-26 13:41:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-26 13:41:16 (GMT) |
commit | 44eafd66882589d4f4eb569d70c49724da3e9291 (patch) | |
tree | eb707056336420eaa04b8d9772c52e57b2a3d0e7 /Lib/idlelib | |
parent | c87876763e88ddbe1d465912aff74ee4c0ffd451 (diff) | |
download | cpython-44eafd66882589d4f4eb569d70c49724da3e9291.zip cpython-44eafd66882589d4f4eb569d70c49724da3e9291.tar.gz cpython-44eafd66882589d4f4eb569d70c49724da3e9291.tar.bz2 |
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.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/run.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 53e80a9..8974b52 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -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 |