From a7bf26e1d83c36490b84c80f72c95c048db06289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rud=C3=A1=20Moura?= Date: Thu, 4 Sep 2014 15:52:16 -0300 Subject: [PATCH] avocado.plugins.xunit: Consider "not found" as error. In the XML output, we can't use an exclusive attribute "not_found" for tests that has been not found. So we're going to count "not found" as error and remove the attribute "not_found". Signed-off-by: Ruda Moura --- avocado/plugins/xunit.py | 9 ++++++--- selftests/all/functional/avocado/basic_tests.py | 13 ++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/avocado/plugins/xunit.py b/avocado/plugins/xunit.py index 7409a198..36a0a6b8 100644 --- a/avocado/plugins/xunit.py +++ b/avocado/plugins/xunit.py @@ -22,6 +22,9 @@ from avocado.plugins import plugin from avocado.result import TestResult +# We use a subset of the XML format defined in this URL: +# https://svn.jenkins-ci.org/trunk/hudson/dtkit/dtkit-format/dtkit-junit-model/src/main/resources/com/thalesgroup/dtkit/junit/model/xsd/junit-4.xsd + class XmlResult(object): """ @@ -46,8 +49,7 @@ class XmlResult(object): """ if filename is None: filename = self.output - xml = '\n'.join(self.xml) - xml += '\n' + xml = '\n'.join(self.xml) + '\n' if filename == '-': sys.stdout.write(xml) else: @@ -60,7 +62,7 @@ class XmlResult(object): :param timestamp: Timestamp string in date/time format. """ - self.testsuite = '' % timestamp + self.testsuite = '' % timestamp self.testcases = [] def end_testsuite(self, tests, errors, not_found, failures, skip, total_time): @@ -73,6 +75,7 @@ class XmlResult(object): :param skip: Number of test skipped. :param total_time: The total time of test execution. """ + errors += not_found # In XML count "not found tests" as error values = {'tests': tests, 'errors': errors, 'not_found': not_found, diff --git a/selftests/all/functional/avocado/basic_tests.py b/selftests/all/functional/avocado/basic_tests.py index 33ef5c8b..aec24d3d 100644 --- a/selftests/all/functional/avocado/basic_tests.py +++ b/selftests/all/functional/avocado/basic_tests.py @@ -411,8 +411,8 @@ class PluginsXunitTest(PluginsTest): self.assertEqual(len(testsuite_list), 1, 'More than one testsuite tag') testsuite_tag = testsuite_list[0] - self.assertEqual(len(testsuite_tag.attributes), 8, - 'The testsuite tag does not have 8 attributes. ' + self.assertEqual(len(testsuite_tag.attributes), 7, + 'The testsuite tag does not have 7 attributes. ' 'XML:\n%s' % xml_output) n_tests = int(testsuite_tag.attributes['tests'].value) @@ -425,11 +425,6 @@ class PluginsXunitTest(PluginsTest): "Unexpected number of test errors, " "XML:\n%s" % xml_output) - n_not_found = int(testsuite_tag.attributes['not_found'].value) - self.assertEqual(n_not_found, e_nnotfound, - "Unexpected number of test not found, " - "XML:\n%s" % xml_output) - n_failures = int(testsuite_tag.attributes['failures'].value) self.assertEqual(n_failures, e_nfailures, "Unexpected number of test failures, " @@ -453,11 +448,11 @@ class PluginsXunitTest(PluginsTest): self.run_and_check('errortest', 1, 1, 1, 0, 0, 0) def test_xunit_plugin_notfoundtest(self): - self.run_and_check('sbrubles', 1, 1, 0, 1, 0, 0) + self.run_and_check('sbrubles', 1, 1, 1, 0, 0, 0) def test_xunit_plugin_mixedtest(self): self.run_and_check('sleeptest failtest skiptest errortest sbrubles', - 1, 5, 1, 1, 1, 1) + 1, 5, 2, 0, 1, 1) class ParseJSONError(Exception): -- GitLab