From a3d3bcf1374b45547738fc58fdf599653b94ec40 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Fri, 20 Sep 2019 13:01:43 +0300 Subject: [PATCH] Check for vs root tag. Fixes #9 According to the JUnit XML specs: https://www.ibm.com/support/knowledgecenter/en/SSUFAU_1.0.0/com.ibm.rsar.analysis.codereview.cobol.doc/topics/cac_useresults_junit.html the root element in the XML is a tag. However some of the test runners we've used skip that and have a single tag as their root node. This causes failures for people using some of the other test runners, e.g. - Katalon Studio - exports with the tag - Nose, py.test - export results with the tag --- .gitignore | 1 - tcms_junit_plugin/__init__.py | 13 ++++++++++++- tests/bin/make-junit.xml | 3 +++ tests/data/9.xml | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/data/9.xml diff --git a/.gitignore b/.gitignore index 4f36722..3c85039 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ dist/ *.egg-info/ .coverage .venv/ -*.xml build/ diff --git a/tcms_junit_plugin/__init__.py b/tcms_junit_plugin/__init__.py index 43a8db2..fa2520b 100644 --- a/tcms_junit_plugin/__init__.py +++ b/tcms_junit_plugin/__init__.py @@ -14,7 +14,18 @@ def parse(self, junit_xml, progress_cb=None): self.backend.configure() xml = JUnitXml.fromfile(junit_xml) - for xml_case in xml: + # apparently junit.xml may contain either a tag, + # e.g. Katalon Studio + if xml._tag == "testsuites": # pylint: disable=protected-access + cases = [] + for suite in xml: + for case in suite: + cases.append(case) + # or directly (only 1) tag - nose & py.test + else: + cases = list(xml) + + for xml_case in cases: summary = "%s.%s" % (xml_case.classname, xml_case.name) test_case = self.backend.test_case_get_or_create(summary) diff --git a/tests/bin/make-junit.xml b/tests/bin/make-junit.xml index 442606f..61e0ded 100755 --- a/tests/bin/make-junit.xml +++ b/tests/bin/make-junit.xml @@ -18,3 +18,6 @@ export TCMS_BUILD="$TRAVIS_BUILD_NUMBER-$(echo $TRAVIS_COMMIT | cut -c1-7)" nosetests --with-xunit ./tcms-junit.xml-plugin nosetests.xml + +# parse additional data files collected from issues +./tcms-junit.xml-plugin tests/data/9.xml diff --git a/tests/data/9.xml b/tests/data/9.xml new file mode 100644 index 0000000..0afe0e0 --- /dev/null +++ b/tests/data/9.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + 2019-05-15 10:46:06 - [TEST_CASE][FAILED] - Test Cases/Simple Examples/Login Test/Data-driven examples/Login with username and password as a default value of variables: Test Cases/Simple Examples/Login Test/Data-driven examples/Login with username and password as a default value of variables FAILED. + 2019-05-15 10:46:06 - [TEST_CASE][FAILED] - Test Cases/Simple Examples/Login Test/Data-driven examples/Login with username and password as a default value of variables: Test Cases/Simple Examples/Login Test/Data-driven examples/Login with username and password as a default value of variables FAILED. + + 2019-05-15 10:46:05 - [TEST_SUITE][INCOMPLETE] - Login test suite with data-driven-approach: null + 2019-05-15 10:46:05 - [TEST_SUITE][INCOMPLETE] - Login test suite with data-driven-approach: null + +