From 35d3baaa2fab0feb9e66a7603bb1dfa2178f2de4 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 25 Nov 2020 11:50:22 +0100 Subject: [PATCH] mtest: improvements to JUnit XML generation Omit the classname attribute, as it is optional, and add the duration. Signed-off-by: Paolo Bonzini --- mesonbuild/mtest.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index fe9104048..d59bb3f1e 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -620,12 +620,13 @@ class JunitBuilder(TestLogger): failures=str(sum(1 for r in test.results.values() if r in {TestResult.FAIL, TestResult.UNEXPECTEDPASS, TestResult.TIMEOUT})), 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(): - # Both name and classname are required. Set them both to the - # number of the test in a TAP test, as TAP doesn't give names. - testcase = et.SubElement(suite, 'testcase', name=i, classname=i) + for i, result in enumerate(test.results): + # Set the name to the number of the test in a TAP test, as we cannot + # access the name yet. + testcase = et.SubElement(suite, 'testcase', name=str(i)) if result is TestResult.SKIP: et.SubElement(testcase, 'skipped') elif result is TestResult.ERROR: @@ -651,12 +652,13 @@ class JunitBuilder(TestLogger): if test.project not in self.suites: suite = self.suites[test.project] = et.Element( 'testsuite', name=test.project, tests='1', errors='0', - failures='0', skipped='0') + failures='0', skipped='0', time=str(test.duration)) else: suite = self.suites[test.project] 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: et.SubElement(testcase, 'skipped') suite.attrib['skipped'] = str(int(suite.attrib['skipped']) + 1)