From 3652751b0bd15fff8430e97224f82f5e2c931269 Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Sun, 23 Nov 2014 23:05:02 -0200 Subject: [PATCH] avocado.job: If possible, write an HTML report at the job results dir If the HTML plugin is enabled on this install, write a report at html/ on that job results directory. This will help people to read avocado test results on a portable and pleasant way. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/job.py | 18 ++++++++++++++++++ avocado/result.py | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/avocado/job.py b/avocado/job.py index b91df302..d00015b1 100644 --- a/avocado/job.py +++ b/avocado/job.py @@ -43,6 +43,11 @@ from avocado import sysinfo from avocado import runtime from avocado.plugins import xunit from avocado.plugins import jsonresult +try: + from avocado.plugins import htmlresult + HTML_REPORT_SUPPORT = True +except ImportError: + HTML_REPORT_SUPPORT = False _NEW_ISSUE_LINK = 'https://github.com/avocado-framework/avocado/issues/new' @@ -388,6 +393,19 @@ class Job(object): json_plugin = jsonresult.JSONTestResult(self.view, args) self.result_proxy.add_output_plugin(json_plugin) + # Setup the json plugin to output to the debug directory + if HTML_REPORT_SUPPORT: + html_file = os.path.join(self.logdir, 'html', 'results.html') + args = argparse.Namespace() + args.html_output = html_file + if self.args is not None: + args.open_browser = getattr(self.args, 'open_browser') + else: + args.open_browser = False + args.relative_links = True + html_plugin = htmlresult.HTMLTestResult(self.view, args) + self.result_proxy.add_output_plugin(html_plugin) + op_set_stdout = self.result_proxy.output_plugins_using_stdout() if len(op_set_stdout) > 1: msg = ('Options %s are trying to use stdout simultaneously' % diff --git a/avocado/result.py b/avocado/result.py index b6e06fdb..69236b1e 100644 --- a/avocado/result.py +++ b/avocado/result.py @@ -20,6 +20,8 @@ It also contains the most basic test result class, HumanTestResult, used by the test runner. """ +import os + class InvalidOutputPlugin(Exception): pass @@ -253,6 +255,11 @@ class HumanTestResult(TestResult): TestResult.start_tests(self) self.stream.notify(event="message", msg="JOB ID : %s" % self.stream.job_unique_id) self.stream.notify(event="message", msg="JOB LOG : %s" % self.stream.logfile) + if self.args is not None: + if 'html_output' in self.args: + logdir = os.path.dirname(self.stream.logfile) + html_file = os.path.join(logdir, 'html', 'results.html') + self.stream.notify(event="message", msg="JOB HTML : %s" % html_file) self.stream.notify(event="message", msg="TESTS : %s" % self.tests_total) self.stream.set_tests_info({'tests_total': self.tests_total}) -- GitLab