Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_file() blows up if prettyprint=False #3

Open
tpbradt opened this issue Mar 15, 2013 · 2 comments
Open

to_file() blows up if prettyprint=False #3

tpbradt opened this issue Mar 15, 2013 · 2 comments

Comments

@tpbradt
Copy link

tpbradt commented Mar 15, 2013

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")

@brianebeyer
Copy link
Contributor

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.

@desolat
Copy link
Contributor

desolat commented Jun 18, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants