mtest: improvements to JUnit XML generation

Omit the classname attribute, as it is optional, and add the duration.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pull/8029/head
Paolo Bonzini 4 years ago
parent 723c4c9fef
commit 35d3baaa2f
  1. 14
      mesonbuild/mtest.py

@ -620,12 +620,13 @@ class JunitBuilder(TestLogger):
failures=str(sum(1 for r in test.results.values() if r in failures=str(sum(1 for r in test.results.values() if r in
{TestResult.FAIL, TestResult.UNEXPECTEDPASS, TestResult.TIMEOUT})), {TestResult.FAIL, TestResult.UNEXPECTEDPASS, TestResult.TIMEOUT})),
skipped=str(sum(1 for r in test.results.values() if r is TestResult.SKIP)), skipped=str(sum(1 for r in test.results.values() if r is TestResult.SKIP)),
time=str(test.duration),
) )
for i, result in test.results.items(): for i, result in enumerate(test.results):
# Both name and classname are required. Set them both to the # Set the name to the number of the test in a TAP test, as we cannot
# number of the test in a TAP test, as TAP doesn't give names. # access the name yet.
testcase = et.SubElement(suite, 'testcase', name=i, classname=i) testcase = et.SubElement(suite, 'testcase', name=str(i))
if result is TestResult.SKIP: if result is TestResult.SKIP:
et.SubElement(testcase, 'skipped') et.SubElement(testcase, 'skipped')
elif result is TestResult.ERROR: elif result is TestResult.ERROR:
@ -651,12 +652,13 @@ class JunitBuilder(TestLogger):
if test.project not in self.suites: if test.project not in self.suites:
suite = self.suites[test.project] = et.Element( suite = self.suites[test.project] = et.Element(
'testsuite', name=test.project, tests='1', errors='0', 'testsuite', name=test.project, tests='1', errors='0',
failures='0', skipped='0') failures='0', skipped='0', time=str(test.duration))
else: else:
suite = self.suites[test.project] suite = self.suites[test.project]
suite.attrib['tests'] = str(int(suite.attrib['tests']) + 1) suite.attrib['tests'] = str(int(suite.attrib['tests']) + 1)
testcase = et.SubElement(suite, 'testcase', name=test.name, classname=test.name) testcase = et.SubElement(suite, 'testcase', name=test.name,
time=str(test.duration))
if test.res is TestResult.SKIP: if test.res is TestResult.SKIP:
et.SubElement(testcase, 'skipped') et.SubElement(testcase, 'skipped')
suite.attrib['skipped'] = str(int(suite.attrib['skipped']) + 1) suite.attrib['skipped'] = str(int(suite.attrib['skipped']) + 1)

Loading…
Cancel
Save