Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f35bb9e

Browse files
committed
Issue #27611, #24137: Only change tkinter when easily restored.
1 parent ee454a0 commit f35bb9e

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

Lib/idlelib/pyshell.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from code import InteractiveInterpreter
3131
from platform import python_version, system
3232

33+
from idlelib import testing
3334
from idlelib.editor import EditorWindow, fixwordbreaks
3435
from idlelib.filelist import FileList
3536
from idlelib.colorizer import ColorDelegator
@@ -1448,8 +1449,9 @@ def main():
14481449
enable_edit = enable_edit or edit_start
14491450
enable_shell = enable_shell or not enable_edit
14501451

1451-
# Setup root.
1452-
if use_subprocess: # Don't break user code run in IDLE process
1452+
# Setup root. Don't break user code run in IDLE process.
1453+
# Don't change environment when testing.
1454+
if use_subprocess and not testing:
14531455
NoDefaultRoot()
14541456
root = Tk(className="Idle")
14551457
root.withdraw()

Lib/test/test_idle.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import unittest
22
from test.support import import_module
33

4-
# Skip test if _thread or _tkinter wasn't built, or idlelib is missing,
5-
# or if tcl/tk version before 8.5, which is needed for ttk widgets.
6-
4+
# Skip test if _thread or _tkinter wasn't built, if idlelib is missing,
5+
# or if tcl/tk is not the 8.5+ needed for ttk widgets.
76
import_module('threading') # imported by PyShell, imports _thread
87
tk = import_module('tkinter') # imports _tkinter
98
if tk.TkVersion < 8.5:
109
raise unittest.SkipTest("IDLE requires tk 8.5 or later.")
11-
tk.NoDefaultRoot()
1210
idlelib = import_module('idlelib')
13-
idlelib.testing = True # Avoid locale-changed test error
1411

15-
# Without test_main present, test.libregrtest.runtest.runtest_inner
16-
# calls (line 173) unittest.TestLoader().loadTestsFromModule(module)
17-
# which calls load_tests() if it finds it. (Unittest.main does the same.)
12+
# Before test imports, tell IDLE to avoid changing the environment.
13+
idlelib.testing = True
14+
15+
# unittest.main and test.libregrtest.runtest.runtest_inner
16+
# call load_tests, when present, to discover tests to run.
1817
from idlelib.idle_test import load_tests
1918

2019
if __name__ == '__main__':
21-
unittest.main(verbosity=2, exit=False)
20+
tk.NoDefaultRoot()
21+
unittest.main(exit=False)
2222
tk._support_default_root = 1
2323
tk._default_root = None

0 commit comments

Comments
 (0)