Skip to content

junit xml "tests" number seems wrong if only teardown fails #3850

@julianheinzelmann

Description

@julianheinzelmann

Hi all,
I am using pytest 3.7.1 to run some tests and output the results using the --junitxml=file.xml argument.
Next the generated xml files are parsed by xunitparser.

I noticed, that for some testcases I run, the parsing failes, as the parser checks if the number of test cases in the report matches the tests="..." information in the header of the xml file.

The following sample test module shows the problem:
(had to rename .py to .txt)
SampletestCase2.txt

run with
python -m pytest SampletestCase2.py --junitxml=fail.xml

now the xml file looks as follows:
fail.txt

There are two <testcase>...</testcase> sections, but the header says: tests="4"
This causes an failed assertion in xunitparser

Therefore: If my asumption is correct, that the tests count in the header of the xml file should match the number of testcase sections in the xml file, then pytest outputs the wrong tests number in case ONLY the teardown failes.

I found a quick workaround (please ignore in case the above assumption is wrong and the xml format is valid, but the error is in the parser)
As i am very new to pytest internals I do not know the possible side effects, but seems to fix my problem...

In the pytest_runtest_logreport function in the file junitxml.py of pytest:

Modifying the increment of the self.cnt_double_fail_tests parameter by introducing the bool incDoubleFail, which is used to determine if there was a true double failure or not. Just at the end of the function the final decision is taken, whether the counter should be incremented.

modified_pytest_runtest_logreport.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: junitxmlrelated to the junitxml builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions