Created
March 19, 2021 00:10
-
-
Save jmhale/f976bb502b578b063b52c90451ae903f to your computer and use it in GitHub Desktop.
Parse Checkov JUnitXML output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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