Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testsuites tag in Junit xml is not handled #9

Closed
hhajni opened this issue May 14, 2019 · 3 comments
Closed

Testsuites tag in Junit xml is not handled #9

hhajni opened this issue May 14, 2019 · 3 comments

Comments

@hhajni
Copy link

hhajni commented May 14, 2019

In order to make this plugin work with the JUnit xmls of my automated tests, I have to remove the XML tag testsuites

In the JUnitParser documentation (https://pypi.org/project/junitparser/) the example shows the levels correctly:
image

The plugin on the other hand assumes that after reading the file, the next level are the testcases:
xml = JUnitXml.fromfile(junit_xml) for xml_case in xml: summary = "%s.%s" % (xml_case.classname, xml_case.name)

Please fix it to avoid the extra step before using the plugin.

@atodorov
Copy link
Member

Can you post a XML file to reproduce?

The file produced by nosetest looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="nosetests" tests="2" errors="0" failures="0" skip="0">
    <testcase classname="tests.test_main.MainFuncTestCase" name="test_when_calling_main_with_arguments_then_parse" time="0.001">
    </testcase>
    <testcase classname="tests.test_main.MainFuncTestCase" name="test_when_calling_main_without_arguments_then_usage" time="0.000">
    </testcase>
</testsuite>

which works just fine without iterating over suites. With the change proposed in the docs I get:

Traceback (most recent call last):
  File "./tcms-junit.xml-plugin", line 11, in <module>
    main(sys.argv)
  File "/home/travis/build/kiwitcms/junit.xml-plugin/tcms_junit_plugin/__init__.py", line 60, in main
    plugin.parse(argv[1])
  File "/home/travis/build/kiwitcms/junit.xml-plugin/tcms_junit_plugin/__init__.py", line 18, in parse
    for xml_case in suite:
TypeError: 'TestCase' object is not iterable

https://travis-ci.org/kiwitcms/junit.xml-plugin/jobs/532434434

so without an actual reproducer we can't do anything else.

@hhajni
Copy link
Author

hhajni commented May 15, 2019

Here's an example output from Katalon Studio, which I use for automation. ( I deleted some unnecessary text)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<testsuites name="Login test suite with data-driven-approach" time="102" tests="0" failures="1" errors="0">
   <testsuite name="Login test suite with data-driven-approach" tests="0" failures="1" errors="0" time="102" timestamp="2019-05-15 10:46:05" hostname="hostname" id="Test Suites/Simple Examples/Login test suite with data-driven-approach">
       <properties>
           <property name="deviceName" value=""/>
           <property name="devicePlatform" value=""/>
           <property name="os" value="Windows 10 64bit"/>
           <property name="katalonVersion" value="6.1.5.3"/>
           <property name="browser" value="Chrome 74.0.3729.131"/>
           <property name="hostAddress" value="10.0.75.1"/>
           <property name="sessionId" value="be95c805dbf972b86c5e147e4cf50990"/>
           <property name="seleniumVersion" value="3.7.1"/>
           <property name="proxyInformation" value="ProxyInformation{proxyOption=NO_PROXY, proxyServerType=HTTP, password=, proxyServerAddress=, proxyServerPort=0}"/>
           <property name="platform" value="Windows 10"/>
       </properties>
       <testcase name="Test Cases/Simple Examples/Login Test/Data-driven examples/Login with username and password as a default value of variables" classname="Test Cases/Simple Examples/Login Test/Data-driven examples/Login with username and password as a default value of variables" status="FAILED">
           <failure type="FAILED" message="Test Cases/Simple Examples/Login Test/Data-driven examples/Login with username and password as a default value of variables FAILED.&#xA;Reason:&#xA;com.kms.katalon.core.exception.StepFailedException: Unable to verify text 'System dashboard' is present &#xD;&#xA;&#x9;at "/>
           <system-out>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.</system-out>
           <system-err>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.</system-err>
       </testcase>
       <system-out>2019-05-15 10:46:05 - [TEST_SUITE][INCOMPLETE] - Login test suite with data-driven-approach: null</system-out>
       <system-err>2019-05-15 10:46:05 - [TEST_SUITE][INCOMPLETE] - Login test suite with data-driven-approach: null</system-err>
   </testsuite>
</testsuites>

Also there's an example at the schema documentation here for the Apache Ant JUnit XML Schema.

It seems nosetest uses a different schema than others.

@asfaltboy
Copy link

True that it's not very common to have many testsuites, especially for automated python test runner frameworks (pytest does the same as nose), it is still valid JUnit spec and should be supported.

For example, we could add the following, just before the original loop:

if xml._tag == "testsuites":
  cases = [case for cases in xml for case in cases]
else:
  cases = list(xml)

atodorov added a commit that referenced this issue Sep 20, 2019
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 <testsuites> tag. However some
of the test runners we've used skip that and have a single
<testsuite> tag as their root node. This causes failures for
people using some of the other test runners, e.g.

- Katalon Studio - exports with the <testsuites> tag
- Nose, py.test - export results with the <testsuite> tag
atodorov added a commit that referenced this issue Sep 20, 2019
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 <testsuites> tag. However some
of the test runners we've used skip that and have a single
<testsuite> tag as their root node. This causes failures for
people using some of the other test runners, e.g.

- Katalon Studio - exports with the <testsuites> tag
- Nose, py.test - export results with the <testsuite> tag
atodorov added a commit that referenced this issue Sep 20, 2019
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 <testsuites> tag. However some
of the test runners we've used skip that and have a single
<testsuite> tag as their root node. This causes failures for
people using some of the other test runners, e.g.

- Katalon Studio - exports with the <testsuites> tag
- Nose, py.test - export results with the <testsuite> tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants