Skip to content

Commit b28a375

Browse files
committed
Issue #18081: Workaround "./python -m test_idle test_logging" failure
"import idlelib" should not install hooks on the warning modules, hooks should only be installed when IDLE is started.
1 parent 7660b88 commit b28a375

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

Lib/idlelib/PyShell.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def idle_showwarning(message, category, filename, lineno,
6161
lineno, line=line))
6262
except OSError:
6363
pass ## file (probably __stderr__) is invalid, warning dropped.
64-
warnings.showwarning = idle_showwarning
6564
def idle_formatwarning(message, category, filename, lineno, line=None):
6665
"""Format warnings the IDLE way"""
6766
s = "\nWarning (from warnings module):\n"
@@ -73,7 +72,6 @@ def idle_formatwarning(message, category, filename, lineno, line=None):
7372
s += " %s\n" % line
7473
s += "%s: %s\n>>> " % (category.__name__, message)
7574
return s
76-
warnings.formatwarning = idle_formatwarning
7775

7876
def extended_linecache_checkcache(filename=None,
7977
orig_checkcache=linecache.checkcache):
@@ -1425,6 +1423,9 @@ def close(self):
14251423
def main():
14261424
global flist, root, use_subprocess
14271425

1426+
warnings.showwarning = idle_showwarning
1427+
warnings.formatwarning = idle_formatwarning
1428+
14281429
use_subprocess = True
14291430
enable_shell = False
14301431
enable_edit = False

Lib/idlelib/run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def idle_formatwarning_subproc(message, category, filename, lineno,
4040
s += " %s\n" % line
4141
s += "%s: %s\n" % (category.__name__, message)
4242
return s
43-
warnings.formatwarning = idle_formatwarning_subproc
4443

4544

4645
tcl = tkinter.Tcl()
@@ -82,6 +81,9 @@ def main(del_exitfunc=False):
8281
global exit_now
8382
global quitting
8483
global no_exitfunc
84+
85+
warnings.formatwarning = idle_formatwarning_subproc
86+
8587
no_exitfunc = del_exitfunc
8688
#time.sleep(15) # test subprocess not responding
8789
try:

0 commit comments

Comments
 (0)