Issues

Issue #414 resolved

UnicodeDecodeError while generating JUnit report

Oliver Ainsworth avatarOliver Ainsworth created an issue

While attempting to generate an JUnit results file, it fails in a way that resembles what was highlighted in #368.

The invocation:

py.test valve --junitxml=junit.xml

The result:

============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
collected 67 items

valve/source/tests/test_message.py ................
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/main.py", line 81, in wrap_session
INTERNALERROR>     doit(config, session)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/main.py", line 117, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 376, in __call__
INTERNALERROR>     return self._docall(methods, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 387, in _docall
INTERNALERROR>     res = mc.execute()
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 288, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/main.py", line 137, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 376, in __call__
INTERNALERROR>     return self._docall(methods, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 387, in _docall
INTERNALERROR>     res = mc.execute()
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 288, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/runner.py", line 62, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/runner.py", line 72, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/runner.py", line 110, in call_and_report
INTERNALERROR>     hook.pytest_runtest_logreport(report=report)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/main.py", line 161, in call_matching_hooks
INTERNALERROR>     return hookmethod.pcall(plugins, **kwargs)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 380, in pcall
INTERNALERROR>     return self._docall(methods, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 387, in _docall
INTERNALERROR>     res = mc.execute()
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/core.py", line 288, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/junitxml.py", line 174, in pytest_runtest_logreport
INTERNALERROR>     self._opentestcase(report)
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/junitxml.py", line 106, in _opentestcase
INTERNALERROR>     name=bin_xml_escape(names[-1]),
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/_pytest/junitxml.py", line 60, in bin_xml_escape
INTERNALERROR>     return py.xml.raw(illegal_xml_re.sub(repl, py.xml.escape(arg)))
INTERNALERROR>   File "/var/lib/jenkins/workspace/unit-tests/local/lib/python2.7/site-packages/py/_xmlgen.py", line 247, in __call__
INTERNALERROR>     ustring = unicode(ustring)
INTERNALERROR> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd8 in position 24: ordinal not in range(128)
========================== 16 passed in 0.14 seconds ==========================

Looking through the tests, the following seems to be the culprit.

@pytest.mark.parametrize("field,value,expected", [
        (messages.ByteField, 26, b"\x1A"),
        (messages.ShortField, 4056, b"\xD8\x0F"),
        (messages.LongField, 2394838, b"\xD6\x8A\x24\x00"),
        (messages.FloatField, 1.0, b"\x00\x00\x80\x3F"),
        (messages.MSAddressEntryPortField, 6969, b"\x1B\x39")
    ])
    def test_encode(self, field, value, expected):
        encoded = field("").encode(value)
        assert isinstance(encoded, bytes)
        assert encoded == expected

Specifically the ShortField test.

Comments (4)

  1. Floris Bruynooghe

    Any chance you could create a stand-alone example of this failure? I failed to reproduce this and have no idea what messages.ShortField("").encode(4056) produces in your case (I presume it's trying to pack an int into 2 bytes but that's no help). At the very least a pointer to where this code might live could help if it's publicly available.

    Thanks

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.