Skip to content

Instantly share code, notes, and snippets.

@renefritze
Created April 2, 2020 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renefritze/14c5f2d79694ff746e7b0905a773e03c to your computer and use it in GitHub Desktop.
Save renefritze/14c5f2d79694ff746e7b0905a773e03c to your computer and use it in GitHub Desktop.
report on cumulative times for a junit xml file
import sys
from collections import defaultdict
from junitparser import JUnitXml
import os
from tabulate import tabulate
def read_files(filenames):
"""expect filenames of the form test_results_GIT-REV.xml
"""
results = {}
for fn in filenames:
assert os.path.isfile(fn), fn
xml = JUnitXml.fromfile(fn)
class_times = defaultdict(lambda : float(0))
case_times = defaultdict(lambda : float(0))
for suite in xml:
# handle suites
for case in suite:
class_times[case.classname] += case.time
name_wo_fixture = case.name[:case.name.find('[')]
case_times[f'{case.classname}__{name_wo_fixture}'] += case.time
results[fn] = {'class_times': class_times, 'case_times': case_times}
return results
def report(results, min_time=None):
for fn, res in results.items():
print(fn)
class_times = [(a,b) for a,b in res['class_times'].items() if min_time is None or b>min_time]
case_times = [(a,b) for a,b in res['case_times'].items() if min_time is None or b>min_time]
print(tabulate(class_times, headers=('class name', 'cumulative time (s)'),
floatfmt=(".1f", ".3f"), tablefmt="github"))
print('\n\n')
print(tabulate(case_times, headers=('class name', 'cumulative time (s)'), floatfmt=(".1f", ".3f"), tablefmt="github"))
if __name__ == '__main__':
report(read_files(sys.argv[1:]), min_time=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment