提交 47a5ec2b 编写于 作者: A Amador Pahim

xunit: fix system-out level in xunit output

`system-out` should be in the same level as `failure`, but we are
creating it as a `failure` child.

This patch puts system-out in the same level as `failure` and adds the
functional test to validate all the xunit outputs against the
junit-4.xsd schema.
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 d42a9d82
......@@ -69,8 +69,7 @@ class XUnitResult(Result):
system_out_cdata_content = self._escape_cdata(text_output)
system_out_cdata = document.createCDATASection(system_out_cdata_content)
system_out.appendChild(system_out_cdata)
element.appendChild(system_out)
return element
return element, system_out
def _render(self, result):
document = Document()
......@@ -91,13 +90,19 @@ class XUnitResult(Result):
elif status == 'SKIP':
testcase.appendChild(Element('skipped'))
elif status == 'FAIL':
element = self._create_failure_or_error(document, test, 'failure')
element, system_out = self._create_failure_or_error(document,
test,
'failure')
testcase.appendChild(element)
testcase.appendChild(system_out)
elif status == 'CANCEL':
testcase.appendChild(Element('skipped'))
else:
element = self._create_failure_or_error(document, test, 'error')
element, system_out = self._create_failure_or_error(document,
test,
'error')
testcase.appendChild(element)
testcase.appendChild(system_out)
testsuite.appendChild(testcase)
return document.toprettyxml(encoding='UTF-8')
......
......@@ -13,9 +13,11 @@ import xml.dom.minidom
import zipfile
import unittest
import psutil
import pkg_resources
from lxml import etree
from StringIO import StringIO
from avocado.core import exit_codes
from avocado.utils import astring
from avocado.utils import process
......@@ -1013,6 +1015,8 @@ class PluginsXunitTest(AbsPluginsTest, unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.junit = os.path.abspath(os.path.join(os.path.dirname(__file__),
os.path.pardir, ".data", 'junit-4.xsd'))
super(PluginsXunitTest, self).setUp()
def run_and_check(self, testname, e_rc, e_ntests, e_nerrors,
......@@ -1031,6 +1035,14 @@ class PluginsXunitTest(AbsPluginsTest, unittest.TestCase):
raise ParseXMLError("Failed to parse content: %s\n%s" %
(detail, xml_output))
with open(self.junit, 'r') as f:
xmlschema = etree.XMLSchema(etree.parse(f))
self.assertTrue(xmlschema.validate(etree.parse(StringIO(xml_output))),
"Failed to validate against %s, message:\n%s" %
(self.junit,
xmlschema.error_log.filter_from_errors()))
testsuite_list = xunit_doc.getElementsByTagName('testsuite')
self.assertEqual(len(testsuite_list), 1, 'More than one testsuite tag')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册