From cce08e71bce072aa5395606e0e1273cd7e103380 Mon Sep 17 00:00:00 2001 From: Evgeniy Nikeytsev Date: Wed, 5 Oct 2022 10:12:54 +0300 Subject: [PATCH] Adding xml report in junit format - added junit format xml file output with test run results to pass to CI for generating reports - added txt file output with only new fails for CI to manage new issues - test execution time is set to be collected always despite of time-report generation setting Change-Id: If413ce350103a250ddbb9ee983e05453d792d6bf Signed-off-by: Evgeniy Nikeytsev --- test/runner/runner_base.py | 6 ++++++ test/runner/runner_js.py | 30 ++++++++++++++++++++++++++++++ test/runner/test_base.py | 13 +++++-------- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/test/runner/runner_base.py b/test/runner/runner_base.py index 1b761277a..724685370 100644 --- a/test/runner/runner_base.py +++ b/test/runner/runner_base.py @@ -80,6 +80,12 @@ class Runner: self.report_root = args.report_root if args.report_root is not None else \ path.join(path.sep, "tmp", name, "reports") makedirs(self.report_root, exist_ok=True) + # filename of xml report in junit format + self.test_report_xml = 'report.xml' + # filename of text report of new failures along with path to log + self.test_report_fails = 'failures.txt' + # runner init time + self.start_time = datetime.now() # root directory containing bin folder with binary files self.build_dir = args.build_dir diff --git a/test/runner/runner_js.py b/test/runner/runner_js.py index 6d18d102f..15d241aa8 100644 --- a/test/runner/runner_js.py +++ b/test/runner/runner_js.py @@ -180,6 +180,7 @@ class RunnerJS(Runner): timestamp = int(datetime.timestamp(datetime.now())) failed_tests = [] + new_fails = [] for test_result in self.results: if test_result.excluded: @@ -204,6 +205,8 @@ class RunnerJS(Runner): write_2_file(text_report_path, test_result.get_text_report()) if self.test_env.args.verbose: print(f"Plain text report is saved to {text_report_path}") + if not test_result.ignored: + new_fails.append([test_result.test_id, text_report_path]) if not test_result.passed: if test_result.ignored: @@ -217,6 +220,11 @@ class RunnerJS(Runner): if test_result.ignored: ignored_but_passed.append(test_result) + if new_fails: + write_2_file(path.join(self.report_root, self.test_report_fails), + '\n'.join(' '.join(x) for x in new_fails)) + if self.results: + self.create_xml_report() total_tests = len(self.tests) + self.excluded if self.args.report_format == ReportFormat.HTML.value: @@ -286,3 +294,25 @@ class RunnerJS(Runner): test_lists.extend(glob(glob_expression, recursive=True)) return test_lists + + def create_xml_report(self): + xml_special_chars = {'&' : '&', '<' : '<', '>' : '>', '"' : '"', "'" : "'"} + xml_report = "" + xml_report += ('\n' % + (self.name, self.passed + self.failed + self.excluded_after + self.ignored, + self.failed + self.ignored, self.excluded_after, (datetime.now() - self.start_time).total_seconds())) + for test_result in self.results: + xml_report += ('\n' % + (self.name, test_result.test_id, test_result.time if test_result.time else 0.0)) + if test_result.excluded: + xml_report += ('This test is skipped during execution\n') + elif not test_result.passed: + fail_output = test_result.report.error + for key, val in xml_special_chars.items(): + fail_output = fail_output.replace(key, val) + xml_report += ('%s\n\n' % + (test_result.fail_kind, fail_output)) + xml_report += ('\n') + + xml_report += ('\n') + write_2_file(path.join(self.report_root, self.test_report_xml), xml_report) diff --git a/test/runner/test_base.py b/test/runner/test_base.py index 9be36d01c..9779af310 100644 --- a/test/runner/test_base.py +++ b/test/runner/test_base.py @@ -34,19 +34,16 @@ class Test: self.reproduce += "\n" + ' '.join(cmd) def run(self): - start = 0 - if self.test_env.args.time_report: - start = datetime.now() + start = datetime.now() if self.test_env.args.verbose: print(f"Going to execute: {self.path}") result = self.do_run() - if self.test_env.args.time_report: - finish = datetime.now() - self.time = (finish - start).total_seconds() - if self.test_env.args.verbose: - print(f"{self.path} executed for {round(self.time, 2)}") + finish = datetime.now() + self.time = (finish - start).total_seconds() + if self.test_env.args.verbose: + print(f"{self.path} executed for {round(self.time, 2)}") return result -- Gitee