[XML] Tests cases with multiple test ids present gets copied #162
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.
In testcases where multiple properties has the
test_id
name, only the last value is persisted, which results in only one test being submitted and the previous ones being ignored.A problematic xml file could be structured as such:
When a JUnit XML file is ingested by the cli, it is parsed by the
parse_file
method found withinreaders/junit_xml.py
. During parsing, each element is iterated over. The parser attempt to extract thetest_id
and then and saves it to a global variablecase_id
, this has the downside that when the next element containing atest_id
name is read, it effectively overwrites the currentcase_id
.Issue being resolved: #130
Solution description
To solve this issue, I've introduced a global
copies
variable that "follows" the current case, such that it is automatically reset each time a new test case is being parsed. During parsing the parser now checks if thecase_id
is notNone
(indicating that thecase_id was set by another
test_id). In this event, the
test_idis added to the
copies` array.When the test case is done being parsed and is added to the list of tests cases (
test_cases
variable), the copies are iterated over and each create a deep copy of the currenttest_case
instance, alter their respective case_id and appends it to the list.This results in each test_id becoming an independent test and submitted to TestRail as such.
Changes
Altered
readers/junit_xml.py
:During parsing, now checks if the case id is already set:
Added
copy_coplicate_test_cases method
:Which is called when the parser is done parsing the case.
Potential impacts
The code added should not have any impact as it does alter the flow under the documented scenarioes (i.e. where one test case has one test_id).
All tests also pass.
Steps to test
Create an a junit test file where one testcase contains more than one test_id property.
PR Tasks