Fixed handling unicode longrepr values. Fixes #114.

This commit is contained in:
Tomasz Gajewski 2017-05-28 16:58:40 +02:00 committed by Dave Hunt
parent 4a16b04d1b
commit a0cade6e0c
No known key found for this signature in database
GPG Key ID: 4000D32ABB02F959
2 changed files with 21 additions and 3 deletions

View File

@ -219,9 +219,7 @@ class HTMLReport(object):
def append_log_html(self, report, additional_html):
log = html.div(class_='log')
if report.longrepr:
for line in str(report.longrepr).splitlines():
if not PY3:
line = line.decode('utf-8')
for line in report.longreprtext.splitlines():
separator = line.startswith('_ ' * 10)
if separator:
log.append(line[:80])

View File

@ -537,3 +537,23 @@ class TestHTML:
assert content in html
else:
assert content not in html
@pytest.mark.parametrize('content', [("'foo'"), ("u'\u0081'")])
def test_utf8_longrepr(self, testdir, content):
testdir.makeconftest("""
import pytest
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
if report.when == 'call':
report.longrepr = 'utf8 longrepr: ' + {0}
""".format(content))
testdir.makepyfile("""
def test_fail():
testtext = 'utf8 longrepr: '
assert False
""")
result, html = run(testdir, 'report.html', '--self-contained-html')
assert result.ret
assert 'utf8 longrepr' in html