summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-02 17:24:51 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-02 17:24:51 (GMT)
commitf58087ba29d79feae0eb05b9a3db01ba3b24f163 (patch)
treead7fd1223db0699c6e7d8ecf7758776650e44edb /Lib
parent4d39f6e09a5c0a0e09eb51d678bacd1adaa3f2ca (diff)
downloadcpython-f58087ba29d79feae0eb05b9a3db01ba3b24f163.zip
cpython-f58087ba29d79feae0eb05b9a3db01ba3b24f163.tar.gz
cpython-f58087ba29d79feae0eb05b9a3db01ba3b24f163.tar.bz2
Issue #8533: revert r80694; try a different fix: regrtest uses backslashreplace
error handler for stdout to avoid UnicodeEncodeError (write non-ASCII character to stdout using ASCII encoding)
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/test/regrtest.py15
-rw-r--r--Lib/test/support.py2
2 files changed, 14 insertions, 3 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index ec49b95..a4ebff4 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -376,6 +376,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
elif o in ('-j', '--multiprocess'):
use_mp = int(a)
elif o == '--slaveargs':
+ replace_stdout()
args, kwargs = json.loads(a)
try:
result = runtest(*args, **kwargs)
@@ -514,6 +515,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
else:
tests = iter(selected)
+ replace_stdout()
+
if use_mp:
try:
from threading import Thread
@@ -727,6 +730,14 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
tests.append(modname)
return stdtests + sorted(tests)
+def replace_stdout():
+ """Set stdout encoder error handler to backslashreplace (as stderr error
+ handler) to avoid UnicodeEncodeError when printing a traceback"""
+ stdout = sys.stdout
+ sys.stdout = open(stdout.fileno(), 'w',
+ encoding=stdout.encoding,
+ errors="backslashreplace")
+
def runtest(test, verbose, quiet,
testdir=None, huntrleaks=False, debug=False, use_resources=None):
"""Run a single test.
@@ -939,8 +950,8 @@ def runtest_inner(test, verbose, quiet,
print("test", test, "crashed --", str(type) + ":", value)
sys.stdout.flush()
if verbose or debug:
- traceback.print_exc(file=sys.stderr)
- sys.stderr.flush()
+ traceback.print_exc(file=sys.stdout)
+ sys.stdout.flush()
return FAILED, test_time
else:
if refleak:
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 3c4d5d6..4ea6c05 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -1020,7 +1020,7 @@ def check_impl_detail(**guards):
def _run_suite(suite):
"""Run tests from a unittest.TestSuite-derived class."""
if verbose:
- runner = unittest.TextTestRunner(sys.stderr, verbosity=2)
+ runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
else:
runner = BasicTestRunner()