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

Extra testcases in Junit xml output with pytest #113

Closed
Hebbeman opened this issue Sep 21, 2016 · 5 comments
Closed

Extra testcases in Junit xml output with pytest #113

Hebbeman opened this issue Sep 21, 2016 · 5 comments

Comments

@Hebbeman
Copy link

Hebbeman commented Sep 21, 2016

When running flaky together with pytest using junit xml output:

pytest --junit-xml=result.xml

it appears like each rerun of a flaky test is registered as an extra testcase in the junit xml output with no attributes except time, for example:
<testcase time="0.0019998550415"></testcase>

Is this working as intended?

@comandrei
Copy link

I've had this happen when using pytest==2.9.1
When upgrading to 3.0.3, this is no longer an issue.

@Hebbeman
Copy link
Author

I upgraded to pytest 3.0.3 (was running 3.0.2), but problem persist :(

With a simple hack I can remove the empty testcases before I publish the test result. However, it would be neater if flaky could handle this. Or perhaps I need to upgrade some other dependency?

@kalidasya
Copy link

@Hebbeman can you share your simple hack? I agree flaky should not spam the report with empty test case elements.

@Hebbeman
Copy link
Author

Hebbeman commented Jan 3, 2017

@kalidasya The "hack" simply modifies the JUnitXML file

import shutil
import lxml.etree as et

# The integration of pytest plugin junitxml and python module 'flaky'
# give rise to 'extra' testcases in the result junit-xml file.
#
# This function is a workaround to remove these 'extras'
def delete_flaky_reruns(junitxml_file):
    doc = et.parse(junitxml_file)
    suite = doc.getroot()
    for case in suite:
        try:
            # If the case lack name it is added because of flaky rerun
            name = case.attrib['name']
        except KeyError:
            print "Removing faulty testcase"
            case.getparent().remove(case)

    doc.write(junitxml_file)

@kalidasya
Copy link

@Hebbeman thanks, I thought you hooked it with pytest and you do this on that report object, but indeed we can do it afterwards as well.
Thanks!

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