Skip to content

Instantly share code, notes, and snippets.

@jmhale
Created March 19, 2021 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmhale/f976bb502b578b063b52c90451ae903f to your computer and use it in GitHub Desktop.
Save jmhale/f976bb502b578b063b52c90451ae903f to your computer and use it in GitHub Desktop.
Parse Checkov JUnitXML output
'''
Parses JUnit XML results from Checkov
'''
import os
import html
from junitparser import JUnitXml, Failure, Skipped, Error
PRINT_NO_FAILS = False
def parse_junitxml():
'''
Parse JUnit XML
'''
real_path = os.path.realpath(__file__)
dir_path = os.path.dirname(real_path)
xml_file = os.path.join(dir_path, "checkov_results.xml")
xml = JUnitXml.fromfile(xml_file)
for suite in xml:
if suite.failures == 0 and PRINT_NO_FAILS:
print("[No Failures] %s" % html.unescape(suite.name))
else:
print("[%s of %s tests failed] %s" % (
suite.failures, suite.tests, html.unescape(suite.name)
))
for case in suite:
# print(case.name)
if case.result:
# print(case.result[0])
if isinstance(case.result[0], Failure):
print(' Failure: ', html.unescape(case.result[0].message))
if isinstance(case.result[0], Skipped):
print(' Skipped: ', html.unescape(case.result[0].message))
if isinstance(case.result[0], Error):
print(' Error: ', html.unescape(case.result[0].message))
parse_junitxml()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment