diff --git a/avocado/core/html.py b/avocado/core/html.py index 6e884cf4bbbd6fb73bdd3172f1f598906e6d608c..4bf99684a1f33a2096db407f54b0fd9edb8ddf79 100644 --- a/avocado/core/html.py +++ b/avocado/core/html.py @@ -24,7 +24,6 @@ import urllib import pystache -from . import output from .result import TestResult from ..utils import path as utils_path from ..utils import runtime @@ -189,11 +188,16 @@ class HTMLTestResult(TestResult): command_line_arg_name = '--html' - def __init__(self, stream=None, args=None): - TestResult.__init__(self, stream, args) - self.output = getattr(self.args, 'html_output') - self.args = args - self.view = output.View(app_args=args) + def __init__(self, job, force_html_file=None): + """ + :param job: Job which defines this result + :param force_html_file: Override the output html file location + """ + TestResult.__init__(self, job) + if force_html_file: + self.output = force_html_file + else: + self.output = self.args.html_output self.json = None def start_tests(self): @@ -288,7 +292,7 @@ class HTMLTestResult(TestResult): report_file.write(report_contents) if self.args is not None: - if getattr(self.args, 'open_browser'): + if getattr(self.args, 'open_browser', False): # if possible, put browser in separate process group, so # keyboard interrupts don't affect browser as well as Python setsid = getattr(os, 'setsid', None) diff --git a/avocado/core/job.py b/avocado/core/job.py index fd5daf6ff0e63986a29bb8dd8926e7c5c1e777de..3e3ea6ff8fd795705009fd46268265c280757164 100644 --- a/avocado/core/job.py +++ b/avocado/core/job.py @@ -195,7 +195,7 @@ class Job(object): def _set_output_plugins(self): if getattr(self.args, 'test_result_classes', None) is not None: for klass in self.args.test_result_classes: - test_result_instance = klass(self.view, self.args) + test_result_instance = klass(self) self.result_proxy.add_output_plugin(test_result_instance) def _make_test_result(self): @@ -216,26 +216,18 @@ class Job(object): # Setup the xunit plugin to output to the debug directory xunit_file = os.path.join(self.logdir, 'results.xml') - args = argparse.Namespace() - args.xunit_output = xunit_file - xunit_plugin = xunit.xUnitTestResult(self.view, args) + xunit_plugin = xunit.xUnitTestResult(self, xunit_file) self.result_proxy.add_output_plugin(xunit_plugin) # Setup the json plugin to output to the debug directory json_file = os.path.join(self.logdir, 'results.json') - args = argparse.Namespace() - args.json_output = json_file - json_plugin = jsonresult.JSONTestResult(self.view, args) + json_plugin = jsonresult.JSONTestResult(self, json_file) self.result_proxy.add_output_plugin(json_plugin) # Setup the html output to the results directory if HTML_REPORT_SUPPORT: html_file = os.path.join(self.logdir, 'html', 'results.html') - args = argparse.Namespace() - args.html_output = html_file - args.open_browser = getattr(self.args, 'open_browser', False) - args.relative_links = True - html_plugin = html.HTMLTestResult(self.view, args) + html_plugin = html.HTMLTestResult(self, html_file) self.result_proxy.add_output_plugin(html_plugin) op_set_stdout = self.result_proxy.output_plugins_using_stdout() @@ -249,7 +241,7 @@ class Job(object): sys.exit(exit_codes.AVOCADO_JOB_FAIL) if not op_set_stdout and not self.standalone: - human_plugin = result.HumanTestResult(self.view, self.args) + human_plugin = result.HumanTestResult(self) self.result_proxy.add_output_plugin(human_plugin) def _make_test_suite(self, urls=None): diff --git a/avocado/core/jsonresult.py b/avocado/core/jsonresult.py index e7b8ea8e44d51a39c98bfd160991176281e4d339..8aef730d61a12698351f4799b369a0e579a64850 100644 --- a/avocado/core/jsonresult.py +++ b/avocado/core/jsonresult.py @@ -30,10 +30,17 @@ class JSONTestResult(TestResult): command_line_arg_name = '--json' - def __init__(self, stream=None, args=None): - TestResult.__init__(self, stream, args) - self.output = getattr(self.args, 'json_output', '-') - self.view = output.View(app_args=args) + def __init__(self, job, force_json_file=None): + """ + :param job: Job which defines this result + :param force_html_file: Override the json output file location + """ + TestResult.__init__(self, job) + if force_json_file: + self.output = force_json_file + else: + self.output = getattr(self.args, 'json_output', '-') + self.view = output.View(app_args=self.args) def start_tests(self): """ @@ -67,7 +74,7 @@ class JSONTestResult(TestResult): self.json['tests'].append(t) def _save_json(self): - with open(self.args.json_output, 'w') as j: + with open(self.output, 'w') as j: j.write(self.json) def end_tests(self): @@ -84,7 +91,7 @@ class JSONTestResult(TestResult): 'time': self.total_time }) self.json = json.dumps(self.json) - if self.args.json_output == '-': + if self.output == '-': self.view.notify(event='minor', msg=self.json) else: self._save_json() diff --git a/avocado/core/remote/result.py b/avocado/core/remote/result.py index db5e6df97014dfa629756ddb5e7f2ac94a921906..ca6cae712fd6c33f42e7c9d270ff7e39504bbb7d 100644 --- a/avocado/core/remote/result.py +++ b/avocado/core/remote/result.py @@ -27,14 +27,13 @@ class RemoteTestResult(HumanTestResult): command_line_arg_name = '--remote-hostname' - def __init__(self, stream, args): + def __init__(self, job): """ Creates an instance of RemoteTestResult. - :param stream: an instance of :class:`avocado.core.output.View`. - :param args: an instance of :class:`argparse.Namespace`. + :param job: an instance of :class:`avocado.core.job.Job`. """ - HumanTestResult.__init__(self, stream, args) + HumanTestResult.__init__(self, job) self.test_dir = os.getcwd() self.remote_test_dir = '~/avocado/tests' self.urls = self.args.url @@ -54,6 +53,6 @@ class VMTestResult(RemoteTestResult): command_line_arg_name = '--vm-domain' - def __init__(self, stream, args): - super(VMTestResult, self).__init__(stream, args) + def __init__(self, job): + super(VMTestResult, self).__init__(job) self.vm = None diff --git a/avocado/core/result.py b/avocado/core/result.py index 55fb85a2151db1f554c1bf17518b5174aa3b3a53..68d2e1ef9dccff69e720d86f5c677c935afabf9b 100644 --- a/avocado/core/result.py +++ b/avocado/core/result.py @@ -118,16 +118,15 @@ class TestResult(object): #: inconsistencies come from. command_line_arg_name = None - def __init__(self, stream, args): + def __init__(self, job): """ Creates an instance of TestResult. - :param stream: an instance of :class:`avocado.core.output.View`. - :param args: an instance of :class:`argparse.Namespace`. + :param job: an instance of :class:`avocado.core.job.Job`. """ - self.stream = stream - self.args = args - self.tests_total = getattr(args, 'test_result_total', 1) + self.args = getattr(job, "args", None) + self.stream = getattr(job, "view", None) + self.tests_total = getattr(self.args, 'test_result_total', 1) self.tests_run = 0 self.total_time = 0.0 self.passed = [] diff --git a/avocado/core/xunit.py b/avocado/core/xunit.py index e5361cebad30c3efbdc20637b692b82615e8c932..2761c4bbdf75558306e3e963d252efbe595cd711 100644 --- a/avocado/core/xunit.py +++ b/avocado/core/xunit.py @@ -154,16 +154,19 @@ class xUnitTestResult(TestResult): command_line_arg_name = '--xunit' - def __init__(self, stream=None, args=None): + def __init__(self, job, force_xunit_file=None): """ Creates an instance of xUnitTestResult. - :param stream: an instance of :class:`avocado.core.output.View`. - :param args: an instance of :class:`argparse.Namespace`. + :param job: an instance of :class:`avocado.core.job.Job`. + :param force_xunit_file: Override the output file defined in job.args """ - TestResult.__init__(self, stream, args) - self.output = getattr(self.args, 'xunit_output', '-') - self.stream = output.View(app_args=args) + TestResult.__init__(self, job) + if force_xunit_file: + self.output = force_xunit_file + else: + self.output = getattr(self.args, 'xunit_output', '-') + self.stream = output.View(app_args=self.args) self.xml = XmlResult() def start_tests(self): diff --git a/avocado/plugins/journal.py b/avocado/plugins/journal.py index fdae552025d3d154666f91a5c1897ef58bd3f2f1..d4a4716ea59c89fdce89ca3f1a1318689f70b18f 100644 --- a/avocado/plugins/journal.py +++ b/avocado/plugins/journal.py @@ -45,14 +45,13 @@ class TestResultJournal(TestResult): command_line_arg_name = '--journal' - def __init__(self, stream=None, args=None): + def __init__(self, job=None): """ Creates an instance of TestResultJournal. - :param stream: an instance of :class:`avocado.core.output.View`. - :param args: an instance of :class:`argparse.Namespace`. + :param job: an instance of :class:`avocado.core.job.Job`. """ - TestResult.__init__(self, stream, args) + TestResult.__init__(self, job) self.journal_initialized = False def _init_journal(self, logdir): diff --git a/selftests/unit/test_jsonresult.py b/selftests/unit/test_jsonresult.py index 899ba61f89053d80088e2d6e34eed9c8ac2829c7..fb5bf0f6851c722f16a5949570583aacfc4e5a41 100644 --- a/selftests/unit/test_jsonresult.py +++ b/selftests/unit/test_jsonresult.py @@ -1,3 +1,4 @@ +from flexmock import flexmock import unittest import os import json @@ -45,7 +46,8 @@ class JSONResultTest(unittest.TestCase): args = argparse.Namespace(json_output=self.tmpfile[1]) stream = _Stream() stream.logfile = 'debug.log' - self.test_result = jsonresult.JSONTestResult(stream, args) + dummyjob = flexmock(view=stream, args=args) + self.test_result = jsonresult.JSONTestResult(dummyjob) self.test_result.filename = self.tmpfile[1] self.test_result.start_tests() self.test1 = SimpleTest(job=job.Job(), base_logdir=self.tmpdir) diff --git a/selftests/unit/test_xunit.py b/selftests/unit/test_xunit.py index d3218ea9f1e00136bd91893cdaa35fc30423c6a3..c07e41f698cf6d6b47fb56f693eab265ee4856b5 100644 --- a/selftests/unit/test_xunit.py +++ b/selftests/unit/test_xunit.py @@ -1,3 +1,4 @@ +from flexmock import flexmock import argparse import unittest import os @@ -48,7 +49,8 @@ class xUnitSucceedTest(unittest.TestCase): self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) args = argparse.Namespace() args.xunit_output = self.tmpfile[1] - self.test_result = xunit.xUnitTestResult(stream=_Stream(), args=args) + dummy_job = flexmock(view=_Stream(), args=args) + self.test_result = xunit.xUnitTestResult(dummy_job) self.test_result.start_tests() self.test1 = SimpleTest(job=job.Job(), base_logdir=self.tmpdir) self.test1.status = 'PASS'