fail-checker.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. import argparse
  3. from typing import List
  4. from junit_utils import iter_xml_files
  5. def check_for_fail(paths: List[str], output_path: str):
  6. failed_list = []
  7. error_list = []
  8. for path in paths:
  9. for fn, suite, case in iter_xml_files(path):
  10. is_failure = case.find("failure") is not None
  11. is_error = case.find("error") is not None
  12. test_name = f"{case.get('classname')}/{case.get('name')}"
  13. if is_failure:
  14. failed_list.append((test_name, fn))
  15. elif is_error:
  16. error_list.append((test_name, fn))
  17. failed_test_count = 0
  18. for t, fn in failed_list:
  19. print(f"failure: {t} ({fn})")
  20. failed_test_count += 1
  21. for t, fn in error_list:
  22. print(f"error: {t} ({fn})")
  23. failed_test_count += 1
  24. if output_path:
  25. with open(output_path, "w") as f:
  26. f.write("{}".format(failed_test_count))
  27. if failed_test_count:
  28. print(f"::error::You have failed tests")
  29. raise SystemExit(-1)
  30. def main():
  31. parser = argparse.ArgumentParser()
  32. parser.add_argument(
  33. "-o",
  34. "--output_path",
  35. metavar="OUTPUT",
  36. help=(
  37. "Output file with count of failed tests"
  38. ),
  39. )
  40. parser.add_argument("path", nargs="+", help="jsuite xml reports directories")
  41. args = parser.parse_args()
  42. check_for_fail(args.path, args.output_path)
  43. if __name__ == "__main__":
  44. main()