kyrus / python-junit-xml

A Python module for creating JUnit XML test result documents that can be read by tools such as Jenkins. If you are ever working with test tool or test suite written in Python and want to take advantage of Jenkins' pretty graphs and test reporting capabilities, this module will let you generate the XML test reports.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

to_file() blows up if prettyprint=False

tpbradt opened this issue · comments

If "prettyprint=False", to_xml_string() converts the xml string to byte instead of string.

File "C:\Python33\Lib\site-packages\junit_xml-1.0-py3.3.egg\junit_xml__init__.py", line 149, in to_file
file_descriptor.write(TestSuite.to_xml_string(test_suites, prettyprint))
TypeError: must be str, not bytes

This is because of the following line in to_xml_string():
xml_string = ET.tostring(xml_element)

which causes ET.tostring() to convert to BytesIO instead of StringIO. The fix is:
xml_string = ET.tostring(xml_element, encoding="unicode")

This must be a Python 2 vs Python 3 issue. I don't know enough about the differences to fix this in a cross-version way. If you have one that works on Python 2 and 3, please send a pull request.

This seems to have been fixed in the meantime as the mentioned line in to_xml_string() uses the given encoding now.