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

Skip to content

Commit e7bb781

Browse files
author
Victor Stinner
committed
Merged revisions 80694,80703 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r80694 | victor.stinner | 2010-05-02 11:37:08 +0200 (dim., 02 mai 2010) | 3 lines Issue #8533: Write tracebacks and failed tests to sys.stderr instead of sys.stdout to avoid UnicodeEncodeError (use backslashreplace error handler) ........ r80703 | victor.stinner | 2010-05-02 19:24:51 +0200 (dim., 02 mai 2010) | 4 lines 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) ........
1 parent 336e54f commit e7bb781

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/test/regrtest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
411411
support.verbose = verbose # Tell tests to be moderately quiet
412412
support.use_resources = use_resources
413413
save_modules = sys.modules.keys()
414+
replace_stdout()
414415
for test in tests:
415416
if not quiet:
416417
print(test)
@@ -556,6 +557,14 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
556557
tests.sort()
557558
return stdtests + tests
558559

560+
def replace_stdout():
561+
"""Set stdout encoder error handler to backslashreplace (as stderr error
562+
handler) to avoid UnicodeEncodeError when printing a traceback"""
563+
stdout = sys.stdout
564+
sys.stdout = open(stdout.fileno(), 'w',
565+
encoding=stdout.encoding,
566+
errors="backslashreplace")
567+
559568
def runtest(test, generate, verbose, quiet, test_times,
560569
testdir=None, huntrleaks=False, debug=False):
561570
"""Run a single test.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ Build
140140
Tests
141141
-----
142142

143+
- Issue #8533: regrtest uses backslashreplace error handler for stdout to avoid
144+
UnicodeEncodeError (write non-ASCII character to stdout using ASCII encoding)
145+
143146
- Issue #8576: Remove use of find_unused_port() in test_smtplib and
144147
test_multiprocessing. Patch by Paul Moore.
145148

0 commit comments

Comments
 (0)