From 3578257173bb18b911c6e6f47e1bbbd071478c0c Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Tue, 10 Jun 2014 20:23:45 -0300 Subject: [PATCH] avocado.job: Prevent 2 output plugins to output to the stdout at the same time With the new attributes, change the output setup procedure to verify if more than one output plugin wants to use the stdout, in which case we print an error message and fail. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/job.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/avocado/job.py b/avocado/job.py index 2a36f1f6..f1c7c695 100644 --- a/avocado/job.py +++ b/avocado/job.py @@ -191,15 +191,31 @@ class Job(object): self.test_runner = test_runner_class(job=self, 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.output_manager, + self.args) + if result_plugin.output == '-': + if plugin_using_stdout is not None: + e_msg %= (plugin_using_stdout.output_option, + result_plugin.output_option) + self.output_manager.log_fail_header(e_msg) + self.output_manager.log_fail_header(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): if self.args: - 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.output_manager, - self.args) - self.result_proxy.add_output_plugin(result_plugin) + self._set_output_plugins() if not self.result_proxy.output_plugins: default_plugin = result.HumanTestResult(self.output_manager, self.args) -- GitLab