xunit-summary.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. import xml.etree.ElementTree as ET
  3. import os
  4. import glob
  5. import ntpath
  6. import sys
  7. if len(sys.argv) < 1:
  8. print("Usage: xunit-summary.py <path to xunit results (*.xml)>")
  9. sys.exit(1)
  10. test_dir = sys.argv [1]
  11. class TestResults():
  12. def __init__(self, name, total, passed, failed, skipped, errors, time):
  13. self.name = name
  14. self.total = total
  15. self.passed = passed
  16. self.failed = failed + errors
  17. self.skipped = skipped
  18. self.time = time
  19. print("")
  20. tests = []
  21. for testfile in glob.glob(test_dir + "/*-xunit.xml"):
  22. assemblies = ET.parse(testfile).getroot()
  23. for assembly in assemblies:
  24. test_name = assembly.attrib.get("name")
  25. if test_name is None:
  26. print("WARNING: %s has no tests!" % ntpath.basename(testfile))
  27. continue
  28. tests.append(TestResults(test_name,
  29. int(assembly.attrib["total"]),
  30. int(assembly.attrib["passed"]),
  31. int(assembly.attrib["failed"]),
  32. int(assembly.attrib["skipped"]),
  33. int(assembly.attrib["errors"]),
  34. float(assembly.attrib["time"])))
  35. # sort by name
  36. tests.sort(key=lambda item: item.name)
  37. print("")
  38. print("=" * 105)
  39. for t in tests:
  40. #if t.failed > 0: # uncomment to list only test suits with failures
  41. print("{0:<60} Total:{1:<6} Failed:{2:<6} Time:{3} sec".format(t.name, t.total, t.failed, round(t.time, 1)))
  42. print("=" * 105)
  43. print("")
  44. print("Total test suits: %d" % len(tests))
  45. print("Total tests run: %d" % sum(x.total for x in tests))
  46. print("Total tests passed: %d" % sum(x.passed for x in tests))
  47. print("Total tests failed: %d" % sum(x.failed for x in tests))
  48. print("Total tests skipped: %d" % sum(x.skipped for x in tests))
  49. print("Total duration: %d min" % (sum(x.time for x in tests) / 60))
  50. print("")