Skip to content

junitxml generates invalid XML characters in failure message #404

Closed
@pytestbot

Description

@pytestbot
Contributor

Originally reported by: BitBucket: davebacher, GitHub: davebacher


The following simple test case generates an invalid XML report -- the report contains invalid characters. This issue looks like the same root cause as #267.

I discovered this problem while investigating a failure reported by Jenkins. The invalid XML characters causes Jenkins to fail to parse the XML test report. I originally encountered this problem with py.test 2.3.4, but it also exists in pytest 2.5.0. I'm using Python 2.7.3.

--- test

#!python

'''Test assertion output'''

M1 = '\x01\x02\x03\x04'
M2 = '\x01\x02\x03\x05'

def test_str_compare():
    assert M1 == M2 #, "compare M1 and M2"

--- xmllint shows the following errors on the result.xml file

#!shell

$ xmllint result.xml
result.xml:4: parser error : PCDATA invalid Char value 1
E         - 
            ^
result.xml:4: parser error : PCDATA invalid Char value 2
E         - 
             ^
result.xml:4: parser error : PCDATA invalid Char value 3
E         - 
              ^
result.xml:4: parser error : PCDATA invalid Char value 4
E         - 
               ^
result.xml:6: parser error : PCDATA invalid Char value 1
E         + 
            ^
result.xml:6: parser error : PCDATA invalid Char value 2
E         + 
             ^
result.xml:6: parser error : PCDATA invalid Char value 3
E         + 
              ^
result.xml:6: parser error : PCDATA invalid Char value 5
E         + 
               ^


Activity

pytestbot

pytestbot commented on Dec 12, 2013

@pytestbot
ContributorAuthor

Original comment by BitBucket: davebacher, GitHub: davebacher:


My current workaround is to specify a failure message when I think the strings might include invalid characters.

#!python

  assert M1 != M2, "M1 does not match M2"
pytestbot

pytestbot commented on Dec 13, 2013

@pytestbot
ContributorAuthor

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


i identified a bug in escaping the assertion analysis information, further investigation is needed to elevate it

pytestbot

pytestbot commented on Dec 13, 2013

@pytestbot
ContributorAuthor

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


the root cause was using the wrong xml escaping primitive
i locally solved the bug and need to review if there are other missuses

pytestbot

pytestbot commented on Dec 13, 2013

@pytestbot
ContributorAuthor

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


fix issue404 by more strict junitxml escape

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pytestbot

        Issue actions

          junitxml generates invalid XML characters in failure message · Issue #404 · pytest-dev/pytest