Skip to content

Instantly share code, notes, and snippets.

@kobenguyent
Forked from cgoldberg/merge_junit_results.py
Last active February 19, 2020 14:16
Show Gist options
  • Select an option

  • Save kobenguyent/5c46ce01734cdfaa9c402eba550fbdd1 to your computer and use it in GitHub Desktop.

Select an option

Save kobenguyent/5c46ce01734cdfaa9c402eba550fbdd1 to your computer and use it in GitHub Desktop.

Revisions

  1. kobenguyent revised this gist Sep 27, 2019. 1 changed file with 15 additions and 33 deletions.
    48 changes: 15 additions & 33 deletions merge_junit_results.py
    Original file line number Diff line number Diff line change
    @@ -6,33 +6,15 @@
    #
    # Copyright (c) 2012 Corey Goldberg
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    # in the Software without restriction, including without limitation the rights
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    # copies of the Software, and to permit persons to whom the Software is
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all
    # copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    # SOFTWARE.
    # Updated by Thanh Nguyen - September 2019

    import os
    import sys
    import xml.etree.ElementTree as ET


    """Merge multiple JUnit XML files into a single results file.
    Output dumps to stdout.
    example usage:
    $ python merge_junit_results.py results1.xml results2.xml > results.xml
    """
    @@ -58,27 +40,27 @@ def merge_results(xml_files):

    for file_name in xml_files:
    tree = ET.parse(file_name)
    test_suite = tree.getroot()
    failures += int(test_suite.attrib['failures'])
    tests += int(test_suite.attrib['tests'])
    errors += int(test_suite.attrib['errors'])
    time += float(test_suite.attrib['time'])
    cases.append(test_suite.getchildren())

    new_root = ET.Element('testsuite')
    new_root.attrib['failures'] = '%s' % failures
    new_root.attrib['tests'] = '%s' % tests
    new_root.attrib['errors'] = '%s' % errors
    new_root.attrib['time'] = '%s' % time
    root = tree.getroot()
    for test_suite in root:
    failures += int(test_suite.attrib['failures'])
    tests += int(test_suite.attrib['tests'])
    errors += int(test_suite.attrib['errors'])
    time += float(test_suite.attrib['time'])
    cases.append(test_suite)

    new_root = ET.Element('testsuites')
    ET.SubElement(new_root, 'testsuite', failures='%s' % failures, tests='%s' % tests, errors='%s' % errors, time='%s' % time)

    for case in cases:
    new_root.extend(case)
    for suite in new_root:
    suite.extend(case)
    new_tree = ET.ElementTree(new_root)
    ET.dump(new_tree)


    def usage():
    this_file = os.path.basename(__file__)
    print 'Usage: %s results1.xml results2.xml' % this_file
    print('Usage: %s results1.xml results2.xml' % this_file)


    if __name__ == '__main__':
  2. @cgoldberg cgoldberg revised this gist Mar 28, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion merge_junit_results.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/usr/bin/env python
    #

    """Merge multiple JUnit XML results files into a single results file."""

    # MIT License
    #
    # Copyright (c) 2012 Corey Goldberg
  3. @cgoldberg cgoldberg revised this gist Mar 28, 2019. 1 changed file with 22 additions and 3 deletions.
    25 changes: 22 additions & 3 deletions merge_junit_results.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,26 @@
    #!/usr/bin/env python
    #
    # Corey Goldberg, Dec 2012
    #
    # MIT License
    #
    # Copyright (c) 2012 Corey Goldberg
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    # in the Software without restriction, including without limitation the rights
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    # copies of the Software, and to permit persons to whom the Software is
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all
    # copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    # SOFTWARE.

    import os
    import sys
    @@ -10,7 +29,7 @@

    """Merge multiple JUnit XML files into a single results file.
    Output dumps to sdtdout.
    Output dumps to stdout.
    example usage:
    $ python merge_junit_results.py results1.xml results2.xml > results.xml
  4. @cgoldberg cgoldberg created this gist Dec 17, 2012.
    64 changes: 64 additions & 0 deletions merge_junit_results.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    #!/usr/bin/env python
    #
    # Corey Goldberg, Dec 2012
    #

    import os
    import sys
    import xml.etree.ElementTree as ET


    """Merge multiple JUnit XML files into a single results file.
    Output dumps to sdtdout.
    example usage:
    $ python merge_junit_results.py results1.xml results2.xml > results.xml
    """


    def main():
    args = sys.argv[1:]
    if not args:
    usage()
    sys.exit(2)
    if '-h' in args or '--help' in args:
    usage()
    sys.exit(2)
    merge_results(args[:])


    def merge_results(xml_files):
    failures = 0
    tests = 0
    errors = 0
    time = 0.0
    cases = []

    for file_name in xml_files:
    tree = ET.parse(file_name)
    test_suite = tree.getroot()
    failures += int(test_suite.attrib['failures'])
    tests += int(test_suite.attrib['tests'])
    errors += int(test_suite.attrib['errors'])
    time += float(test_suite.attrib['time'])
    cases.append(test_suite.getchildren())

    new_root = ET.Element('testsuite')
    new_root.attrib['failures'] = '%s' % failures
    new_root.attrib['tests'] = '%s' % tests
    new_root.attrib['errors'] = '%s' % errors
    new_root.attrib['time'] = '%s' % time
    for case in cases:
    new_root.extend(case)
    new_tree = ET.ElementTree(new_root)
    ET.dump(new_tree)


    def usage():
    this_file = os.path.basename(__file__)
    print 'Usage: %s results1.xml results2.xml' % this_file


    if __name__ == '__main__':
    main()