fix unicode handling with junitxml, fixes issue368.

This commit is contained in:
holger krekel 2013-10-21 16:54:25 +02:00
parent 0d8392bc45
commit cf9d345382
5 changed files with 36 additions and 12 deletions

View File

@ -4,6 +4,8 @@ Changes between 2.4.2 and 2.4.3
- fix unicode handling with new monkeypatch.setattr(import_path, value)
API. Thanks Rob Dennis. Fixes issue371.
- fix unicode handling with junitxml, fixes issue368.
- In assertion rewriting mode on Python 2, fix the detection of coding
cookies. See issue #330.

View File

@ -1,2 +1,2 @@
#
__version__ = '2.4.3.dev1'
__version__ = '2.4.3.dev2'

View File

@ -9,7 +9,6 @@ import re
import sys
import time
# Python 2.X and 3.X compatibility
try:
unichr(65)
@ -131,31 +130,31 @@ class LogXML(object):
self.skipped += 1
else:
fail = Junit.failure(message="test failure")
fail.append(str(report.longrepr))
fail.append(unicode(report.longrepr))
self.append(fail)
self.failed += 1
self._write_captured_output(report)
def append_collect_failure(self, report):
#msg = str(report.longrepr.reprtraceback.extraline)
self.append(Junit.failure(str(report.longrepr),
self.append(Junit.failure(unicode(report.longrepr),
message="collection failure"))
self.errors += 1
def append_collect_skipped(self, report):
#msg = str(report.longrepr.reprtraceback.extraline)
self.append(Junit.skipped(str(report.longrepr),
self.append(Junit.skipped(unicode(report.longrepr),
message="collection skipped"))
self.skipped += 1
def append_error(self, report):
self.append(Junit.error(str(report.longrepr),
self.append(Junit.error(unicode(report.longrepr),
message="test setup failure"))
self.errors += 1
def append_skipped(self, report):
if hasattr(report, "wasxfail"):
self.append(Junit.skipped(str(report.wasxfail),
self.append(Junit.skipped(unicode(report.wasxfail),
message="expected test failure"))
else:
filename, lineno, skipreason = report.longrepr
@ -201,10 +200,10 @@ class LogXML(object):
classname="pytest",
name="internal"))
def pytest_sessionstart(self, session):
def pytest_sessionstart(self):
self.suite_start_time = time.time()
def pytest_sessionfinish(self, session, exitstatus, __multicall__):
def pytest_sessionfinish(self):
if py.std.sys.version_info[0] < 3:
logfile = py.std.codecs.open(self.logfile, 'w', encoding='utf-8')
else:

View File

@ -27,7 +27,7 @@ def main():
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
version='2.4.3.dev1',
version='2.4.3.dev2',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from xml.dom import minidom
import py, sys, os
from _pytest.junitxml import LogXML
def runandparse(testdir, *args):
resultpath = testdir.tmpdir.join("junit.xml")
@ -423,8 +426,6 @@ def test_invalid_xml_escape():
assert chr(i) == bin_xml_escape(unichr(i)).uniobj
def test_logxml_path_expansion(tmpdir, monkeypatch):
from _pytest.junitxml import LogXML
home_tilde = py.path.local(os.path.expanduser('~')).join('test.xml')
xml_tilde = LogXML('~%stest.xml' % tmpdir.sep, None)
@ -461,3 +462,25 @@ def test_escaped_parametrized_names_xml(testdir):
assert_attr(node,
name="test_func[#x00]")
def test_unicode_issue368(testdir):
path = testdir.tmpdir.join("test.xml")
log = LogXML(str(path), None)
class report:
longrepr = u"ВНИМАНИЕ!"
sections = []
nodeid = "something"
# hopefully this is not too brittle ...
log.pytest_sessionstart()
log._opentestcase(report)
log.append_failure(report)
log.append_collect_failure(report)
log.append_collect_skipped(report)
log.append_error(report)
report.longrepr = "filename", 1, u"ВНИМАНИЕ!"
log.append_skipped(report)
report.wasxfail = u"ВНИМАНИЕ!"
log.append_skipped(report)
log.pytest_sessionfinish()