fix issue #178 and extend the failure escape test

This commit is contained in:
Ronny Pfannschmidt 2012-08-17 16:08:08 +02:00
parent aa84359bd9
commit 1446b4b4e6
3 changed files with 18 additions and 13 deletions

View File

@ -42,6 +42,8 @@ Changes between 2.2.4 and 2.3.0.dev
especially with respect to the "magic" history, also mention especially with respect to the "magic" history, also mention
pytest-django, trial and unittest integration. pytest-django, trial and unittest integration.
- fix issue 178: xml binary escapes are now wrapped in py.xml.raw
- reporting refinements: - reporting refinements:
- pytest_report_header now receives a "startdir" so that - pytest_report_header now receives a "startdir" so that

View File

@ -57,7 +57,7 @@ def bin_xml_escape(arg):
return unicode('#x%02X') % i return unicode('#x%02X') % i
else: else:
return unicode('#x%04X') % i return unicode('#x%04X') % i
return illegal_xml_re.sub(repl, py.xml.escape(arg)) return py.xml.raw(illegal_xml_re.sub(repl, py.xml.escape(arg)))
def pytest_addoption(parser): def pytest_addoption(parser):
group = parser.getgroup("terminal reporting") group = parser.getgroup("terminal reporting")

View File

@ -159,24 +159,27 @@ class TestPython:
def test_failure_escape(self, testdir): def test_failure_escape(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
def pytest_generate_tests(metafunc): import pytest
metafunc.addcall(id="<", funcargs=dict(arg1=42)) @pytest.mark.parametrize('arg1', "<&'", ids="<&'")
metafunc.addcall(id="&", funcargs=dict(arg1=44))
def test_func(arg1): def test_func(arg1):
print arg1
assert 0 assert 0
""") """)
result, dom = runandparse(testdir) result, dom = runandparse(testdir)
assert result.ret assert result.ret
node = dom.getElementsByTagName("testsuite")[0] node = dom.getElementsByTagName("testsuite")[0]
assert_attr(node, failures=2, tests=2) assert_attr(node, failures=3, tests=3)
tnode = node.getElementsByTagName("testcase")[0]
for index, char in enumerate("<&'"):
tnode = node.getElementsByTagName("testcase")[index]
assert_attr(tnode, assert_attr(tnode,
classname="test_failure_escape", classname="test_failure_escape",
name="test_func[<]") name="test_func[%s]" % char)
tnode = node.getElementsByTagName("testcase")[1] sysout = tnode.getElementsByTagName('system-out')[0]
assert_attr(tnode, text = sysout.childNodes[0].wholeText
classname="test_failure_escape", assert text == '%s\n' % char
name="test_func[&]")
def test_junit_prefixing(self, testdir): def test_junit_prefixing(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""