Fix __add__: mutated arguments after operation#178
Open
miguelflor wants to merge 3 commits into
Open
Conversation
makes more sense to put the deepcopy inside the function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This started with a issue #177 that I posted.
So I recommend reading it to understand the description of this PR.
Description
I found that after making the add on the Object
JUnitXmlthe arguments would mutate, making the second add with the same arguments different. Which I believe is not desirable.Problem 1
The behavior described in the issue happens because of the function
.append(child)ofetree.The
etreecan come from two libraries as you can see form the snippet taken from the source code:When a the function
.append(child)is called and the child already as a parent, both libraries operate in different ways.lxml
With this library when the .append(child) is trigger it moves each child from the original tree to the new tree.
That explains why in the code I shared in the PR, after the first
+in the logger all the testsuites where moved to a new object and latter garage collected. When the+is called again both vars don't have any tests.xml.etree
This is trickier.
the behavior is actually simpler just gives the child to the new parent, but the child will have two parents at the same time. Although I could not find any error I believe that this can be prone to error.
Problem 2
This problem arises when the arguments of the
__add__where considered under the function__eq__that they had equal suites.Because of the call
_add_testcase_no_update_stats(case), it changes the suites making it with duplicate cases.This error only happens when using
xml.etree, and that's because the values where not move at first.Test
The test made covers both problems at the same time (:
Fix
The fix is actually pretty simple, I just called
deepcopy(suite)in the beginning of the functionadd_testsuite(self, suite).Additional Notes
In the end a lot of yapping for a simple solution. If you have any questions feel free to ask.