aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/run_tests/python_utils/report_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/run_tests/python_utils/report_utils.py')
-rw-r--r--tools/run_tests/python_utils/report_utils.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/tools/run_tests/python_utils/report_utils.py b/tools/run_tests/python_utils/report_utils.py
index 4b4c50a03e..a3867808b5 100644
--- a/tools/run_tests/python_utils/report_utils.py
+++ b/tools/run_tests/python_utils/report_utils.py
@@ -22,6 +22,7 @@ try:
from mako import exceptions
except (ImportError):
pass # Mako not installed but it is ok.
+import datetime
import os
import string
import xml.etree.cElementTree as ET
@@ -43,12 +44,29 @@ def _filter_msg(msg, output_format):
return msg
-def render_junit_xml_report(resultset, xml_report, suite_package='grpc',
+def new_junit_xml_tree():
+ return ET.ElementTree(ET.Element('testsuites'))
+
+def render_junit_xml_report(resultset, report_file, suite_package='grpc',
suite_name='tests'):
"""Generate JUnit-like XML report."""
- root = ET.Element('testsuites')
- testsuite = ET.SubElement(root, 'testsuite', id='1', package=suite_package,
- name=suite_name)
+ tree = new_junit_xml_tree()
+ append_junit_xml_results(tree, resultset, suite_package, suite_name, '1')
+ create_xml_report_file(tree, report_file)
+
+def create_xml_report_file(tree, report_file):
+ """Generate JUnit-like report file from xml tree ."""
+ # ensure the report directory exists
+ report_dir = os.path.dirname(os.path.abspath(report_file))
+ if not os.path.exists(report_dir):
+ os.makedirs(report_dir)
+ tree.write(report_file, encoding='UTF-8')
+
+def append_junit_xml_results(tree, resultset, suite_package, suite_name, id):
+ """Append a JUnit-like XML report tree with test results as a new suite."""
+ testsuite = ET.SubElement(tree.getroot(), 'testsuite',
+ id=id, package=suite_package, name=suite_name,
+ timestamp=datetime.datetime.now().isoformat())
failure_count = 0
error_count = 0
for shortname, results in six.iteritems(resultset):
@@ -67,13 +85,6 @@ def render_junit_xml_report(resultset, xml_report, suite_package='grpc',
ET.SubElement(xml_test, 'skipped', message='Skipped')
testsuite.set('failures', str(failure_count))
testsuite.set('errors', str(error_count))
- # ensure the report directory exists
- report_dir = os.path.dirname(os.path.abspath(xml_report))
- if not os.path.exists(report_dir):
- os.makedirs(report_dir)
- tree = ET.ElementTree(root)
- tree.write(xml_report, encoding='UTF-8')
-
def render_interop_html_report(
client_langs, server_langs, test_cases, auth_test_cases, http2_cases,