summaryrefslogtreecommitdiffstats
path: root/Lib/test/regrtest.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-01-05 03:54:26 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-01-05 03:54:26 (GMT)
commit4b2b43d9889b498c1dc71b8a2bef8cfea45f410c (patch)
treed999c5d2805428a4d6a29b7d34ebbc30de1f740d /Lib/test/regrtest.py
parent358e11d928ae4d3386c17eb0b48e7602029fec06 (diff)
downloadcpython-4b2b43d9889b498c1dc71b8a2bef8cfea45f410c.zip
cpython-4b2b43d9889b498c1dc71b8a2bef8cfea45f410c.tar.gz
cpython-4b2b43d9889b498c1dc71b8a2bef8cfea45f410c.tar.bz2
regrtest: close the new stdout and restore the original stdout at exit
Fix a ResourceWarning(unclosed file).
Diffstat (limited to 'Lib/test/regrtest.py')
-rwxr-xr-xLib/test/regrtest.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 1649865..92d1597 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -743,10 +743,19 @@ def replace_stdout():
if os.name == "nt":
# Replace sys.stdout breaks the stdout newlines on Windows: issue #8533
return
+
+ import atexit
+
stdout = sys.stdout
sys.stdout = open(stdout.fileno(), 'w',
encoding=stdout.encoding,
- errors="backslashreplace")
+ errors="backslashreplace",
+ closefd=False)
+
+ def restore_stdout():
+ sys.stdout.close()
+ sys.stdout = stdout
+ atexit.register(restore_stdout)
def runtest(test, verbose, quiet,
huntrleaks=False, debug=False, use_resources=None):