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

Skip to content

Commit 8dee809

Browse files
committed
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
the local save/modify/restore of sys.stdout, but add machinery so that regrtest can tell test_support the value of sys.stdout at the time regrtest.main() started, and test_support can pass that out later to anyone who needs a "visible" stdout.
1 parent 698acf9 commit 8dee809

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/test/regrtest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
8585
8686
"""
8787

88+
test_support.record_original_stdout(sys.stdout)
8889
try:
8990
opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrlu:',
9091
['help', 'verbose', 'quiet', 'generate',

Lib/test/test_support.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ class TestSkipped(Error):
2121
verbose = 1 # Flag set to 0 by regrtest.py
2222
use_resources = None # Flag set to [] by regrtest.py
2323

24+
# _original_stdout is meant to hold stdout at the time regrtest began.
25+
# This may be "the real" stdout, or IDLE's emulation of stdout, or whatever.
26+
# The point is to have some flavor of stdout the user can actually see.
27+
_original_stdout = None
28+
def record_original_stdout(stdout):
29+
global _original_stdout
30+
_original_stdout = stdout
31+
32+
def get_original_stdout():
33+
return _original_stdout or sys.stdout
34+
2435
def unload(name):
2536
try:
2637
del sys.modules[name]
@@ -182,7 +193,7 @@ def run_doctest(module, verbosity=None):
182193
# Direct doctest output (normally just errors) to real stdout; doctest
183194
# output shouldn't be compared by regrtest.
184195
save_stdout = sys.stdout
185-
sys.stdout = sys.__stdout__
196+
sys.stdout = get_original_stdout()
186197
try:
187198
f, t = doctest.testmod(module, verbose=verbosity)
188199
if f:

0 commit comments

Comments
 (0)