Skip to content

+= is not equal to + when merging JUnitXml variables #177

@miguelflor

Description

@miguelflor

Description of the problem

I can't figure it out how to merge two JUnitXml variables.
And I have different outputs for += and + operators.

Code

Example 1:

JUnitXml.__str__ = lambda self: (
    f"{(self.tests or 0) - (self.failures or 0)}/{self.tests}"
)

logger.debug(
    "Merging: {} with {} = {}",
    junits,
    junits_merge,
    junits + junits_merge,
)
junits_merge += junits_merge
logger.info("Junit Output: {}", junits_merge)

output:

2026-05-12 11:44:03.112 | DEBUG    | __main__:main:149 - Merging: 177/262 with 40/40 = 217/302
2026-05-12 11:44:03.114 | INFO     | __main__:main:157 - Junit Output: 40/40

If I added this line after the += operation:

junits_merge.update_statistics()

The result is the same as Example 2.

Example 2:

JUnitXml.__str__ = lambda self: (
   f"{(self.tests or 0) - (self.failures or 0)}/{self.tests}"
)

logger.debug(
   "Merging: {} with {} = {}",
   junits,
   junits_merge,
   junits + junits_merge,
)
junits_merge = junits +  junits_merge
logger.info("Junit Output: {}", junits_merge)

output:

2026-05-12 12:45:45.671 | DEBUG    | __main__:main:150 - Merging: 177/262 with 40/40 = 217/302
2026-05-12 12:45:45.673 | INFO     | __main__:main:157 - Junit Output: 0/0

Versions

  • Python: 3.12.3
  • junitparser: 5.0.0

Additional notes

If you think there is not enough details feel free to ask for more!
And note that I am considering that the "problem" can be on my side, I am just asking directly to the pros because I am running out of options.
Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions