diff --git a/avocado/job.py b/avocado/job.py index def50b4863c96175c478de4b9d72be2760dd940f..ef40608515bfbd1c02115d04a2a27557e8d3bc20 100644 --- a/avocado/job.py +++ b/avocado/job.py @@ -330,25 +330,12 @@ class Job(object): test_result=self.result_proxy) def _set_output_plugins(self): - plugin_using_stdout = None - e_msg = ("Avocado could not set %s and %s both to output to stdout. ") - e_msg_2 = ("Please set the output flag of one of them to a file " - "to avoid conflicts.") for key in self.args.__dict__: if key.endswith('_result'): result_class = getattr(self.args, key) if issubclass(result_class, result.TestResult): result_plugin = result_class(self.view, self.args) - if result_plugin.output == '-': - if plugin_using_stdout is not None: - e_msg %= (plugin_using_stdout.command_line_arg_name, - result_plugin.command_line_arg_name) - self.view.notify(event='error', msg=e_msg) - self.view.notify(event='error', msg=e_msg_2) - sys.exit(error_codes.numeric_status['AVOCADO_JOB_FAIL']) - else: - plugin_using_stdout = result_plugin self.result_proxy.add_output_plugin(result_plugin) def _make_test_result(self): @@ -381,8 +368,17 @@ class Job(object): json_plugin = jsonresult.JSONTestResult(self.view, args) self.result_proxy.add_output_plugin(json_plugin) - outputs = [op.output for op in self.result_proxy.output_plugins] - if '-' not in outputs: + 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' % + " ".join(op_set_stdout)) + self.view.notify(event='error', msg=msg) + msg = ('Please set at least one of them to a file to avoid ' + 'conflicts') + self.view.notify(event='error', msg=msg) + sys.exit(error_codes.numeric_status['AVOCADO_JOB_FAIL']) + + if not op_set_stdout: human_plugin = result.HumanTestResult(self.view, self.args) self.result_proxy.add_output_plugin(human_plugin) diff --git a/avocado/result.py b/avocado/result.py index f6140187292f9721ab9f8f0f1dedf2232bd2f78d..b6e06fdb595a7e56fb7d8c7af6445bb5aada537f 100644 --- a/avocado/result.py +++ b/avocado/result.py @@ -48,6 +48,13 @@ class TestResultProxy(object): "TestResult" % plugin) self.output_plugins.append(plugin) + def output_plugins_using_stdout(self): + using_stdout = [] + for op in self.output_plugins: + if op.output == '-': + using_stdout.append(op.command_line_arg_name) + return using_stdout + def start_tests(self): for output_plugin in self.output_plugins: output_plugin.start_tests() diff --git a/selftests/all/functional/avocado/output_tests.py b/selftests/all/functional/avocado/output_tests.py index 36e906ee1682955c8c05be12bcb816f7b08f9383..746912eb13b5966d51cfde898a795a937f9b19cf 100644 --- a/selftests/all/functional/avocado/output_tests.py +++ b/selftests/all/functional/avocado/output_tests.py @@ -68,9 +68,9 @@ class OutputPluginTest(unittest.TestCase): self.assertEqual(result.exit_status, expected_rc, "Avocado did not return rc %d:\n%s" % (expected_rc, result)) - error_excerpt = "Avocado could not set --json and --xunit both to output to stdout." + error_excerpt = "Options --json --xunit are trying to use stdout simultaneously" self.assertIn(error_excerpt, output, - "Missing excepted error message from output:\n%s" % output) + "Missing excerpt error message from output:\n%s" % output) def test_output_incompatible_setup_2(self): os.chdir(basedir) @@ -81,9 +81,9 @@ class OutputPluginTest(unittest.TestCase): self.assertEqual(result.exit_status, expected_rc, "Avocado did not return rc %d:\n%s" % (expected_rc, result)) - error_excerpt = "Avocado could not set --json and --vm both to output to stdout." + error_excerpt = "Options --json --vm are trying to use stdout simultaneously" self.assertIn(error_excerpt, output, - "Missing excepted error message from output:\n%s" % output) + "Missing excerpt error message from output:\n%s" % output) def test_output_compatible_setup(self): tmpfile = tempfile.mktemp()