未验证 提交 3aa81b0a 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'apahim/fix_xunit_on_test_fail_v2'

Signed-off-by: NCleber Rosa <crosa@redhat.com>
......@@ -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')
......
......@@ -43,8 +43,8 @@ class xUnitSucceedTest(unittest.TestCase):
self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir)
self.test1._Test__status = 'PASS'
self.test1.time_elapsed = 1.23
unittests_path = os.path.dirname(os.path.abspath(__file__))
self.junit_schema_path = os.path.join(unittests_path, 'junit-4.xsd')
self.junit = os.path.abspath(os.path.join(os.path.dirname(__file__),
os.path.pardir, ".data", 'junit-4.xsd'))
def tearDown(self):
os.close(self.tmpfile[0])
......@@ -67,11 +67,11 @@ class xUnitSucceedTest(unittest.TestCase):
els = dom.getElementsByTagName('testcase')
self.assertEqual(len(els), 1)
with open(self.junit_schema_path, 'r') as f:
with open(self.junit, 'r') as f:
xmlschema = etree.XMLSchema(etree.parse(f))
self.assertTrue(xmlschema.validate(etree.parse(StringIO(xml))),
"Failed to validate against %s, content:\n%s" %
(self.junit_schema_path, xml))
(self.junit, xml))
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册