[py-svn] commit/pytest: hpk42: fix problem with unicode in writing failure representations to terminal, thanks ThomasWaldmann
Bitbucket
commits-noreply at bitbucket.org
Sun Jun 24 16:43:06 CEST 2012
1 new commit in pytest:
https://bitbucket.org/hpk42/pytest/changeset/5bcd225c3b5e/
changeset: 5bcd225c3b5e
user: hpk42
date: 2012-06-24 16:42:31
summary: fix problem with unicode in writing failure representations to terminal, thanks ThomasWaldmann
affected #: 4 files
diff -r 86ea199221ab3ee87432d2f55ed81f9b18da7f04 -r 5bcd225c3b5eb502209b537546ad0f83e40de032 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,12 +1,14 @@
Changes between 2.2.4 and 2.2.5.dev
-----------------------------------
+- catch unicode-issues when writing failure representations
+ to terminal to prevent the whole session from crashing
- fix xfail/skip confusion: a skip-mark or an imperative pytest.skip
will now take precedence before xfail-markers because we
can't determine xfail/xpass status in case of a skip. see also:
http://stackoverflow.com/questions/11105828/in-py-test-when-i-explicitly-skip-a-test-that-is-marked-as-xfail-how-can-i-get
-- always report installed 3rd party plugins
+- always report installed 3rd party plugins in the header of a test run
- fix issue160: a failing setup of an xfail-marked tests should
be reported as xfail (not xpass)
diff -r 86ea199221ab3ee87432d2f55ed81f9b18da7f04 -r 5bcd225c3b5eb502209b537546ad0f83e40de032 _pytest/runner.py
--- a/_pytest/runner.py
+++ b/_pytest/runner.py
@@ -154,7 +154,10 @@
if hasattr(longrepr, 'toterminal'):
longrepr.toterminal(out)
else:
- out.line(str(longrepr))
+ try:
+ out.line(longrepr)
+ except UnicodeEncodeError:
+ out.line("<unprintable longrepr>")
passed = property(lambda x: x.outcome == "passed")
failed = property(lambda x: x.outcome == "failed")
@@ -279,7 +282,7 @@
def __init__(self, msg):
self.longrepr = msg
def toterminal(self, out):
- out.line(str(self.longrepr), red=True)
+ out.line(self.longrepr, red=True)
class SetupState(object):
""" shared state for setting up/tearing down test items or collectors. """
diff -r 86ea199221ab3ee87432d2f55ed81f9b18da7f04 -r 5bcd225c3b5eb502209b537546ad0f83e40de032 _pytest/terminal.py
--- a/_pytest/terminal.py
+++ b/_pytest/terminal.py
@@ -38,13 +38,14 @@
stdout = py.std.sys.stdout
if hasattr(os, 'dup') and hasattr(stdout, 'fileno'):
try:
- newfd = os.dup(stdout.fileno())
- #print "got newfd", newfd
+ newstdout = py.io.dupfile(stdout, buffering=1,
+ encoding=stdout.encoding)
except ValueError:
pass
else:
- stdout = os.fdopen(newfd, stdout.mode, 1)
- config._cleanup.append(lambda: stdout.close())
+ config._cleanup.append(lambda: newstdout.close())
+ assert stdout.encoding == newstdout.encoding
+ stdout = newstdout
reporter = TerminalReporter(config, stdout)
config.pluginmanager.register(reporter, 'terminalreporter')
diff -r 86ea199221ab3ee87432d2f55ed81f9b18da7f04 -r 5bcd225c3b5eb502209b537546ad0f83e40de032 testing/test_runner.py
--- a/testing/test_runner.py
+++ b/testing/test_runner.py
@@ -456,3 +456,21 @@
ret = popen.wait()
assert ret == 0
+
+def test_unicode_in_longrepr(testdir):
+ testdir.makeconftest("""
+ import py
+ def pytest_runtest_makereport(__multicall__):
+ rep = __multicall__.execute()
+ if rep.when == "call":
+ rep.longrepr = py.builtin._totext("\\xc3\\xa4", "utf8")
+ return rep
+ """)
+ testdir.makepyfile("""
+ def test_out():
+ assert 0
+ """)
+ result = testdir.runpytest()
+ assert result.ret == 1
+ assert "UnicodeEncodeError" not in result.stderr.str()
+
Repository URL: https://bitbucket.org/hpk42/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list