From b9357e3b178cad370496fe92efdd8baaa7c6e4af Mon Sep 17 00:00:00 2001 From: Ramiro Polla Date: Fri, 16 Jan 2015 18:42:19 +0100 Subject: [PATCH] validate: launcher: Separate Reporter from current Test Instead of saving the current Test in Reporter for every test, use function parameters to achieve the same goal. Patch 2/5 to move logfile handling out of Reporter and into Test. --- validate/launcher/baseclasses.py | 2 +- validate/launcher/reporters.py | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/validate/launcher/baseclasses.py b/validate/launcher/baseclasses.py index 6ddf36a..308a2d3 100644 --- a/validate/launcher/baseclasses.py +++ b/validate/launcher/baseclasses.py @@ -751,7 +751,7 @@ def run_tests(self, cur_test_num, total_num_tests): self.reporter.before_test(test) res = test.run() i += 1 - self.reporter.after_test() + self.reporter.after_test(test) if res != Result.PASSED and (self.options.forever or self.options.fatal_error): return test.result diff --git a/validate/launcher/reporters.py b/validate/launcher/reporters.py index ac3460d..ba4e4a2 100644 --- a/validate/launcher/reporters.py +++ b/validate/launcher/reporters.py @@ -55,7 +55,6 @@ class Reporter(Loggable): def __init__(self, options): Loggable.__init__(self) - self._current_test = None self.out = None self.options = options self._start_time = 0 @@ -82,7 +81,6 @@ def before_test(self, test): self.out = sys.stderr else: self.out = open(path, 'w+') - self._current_test = test def set_failed(self, test): self.stats["failure"] += 1 @@ -100,16 +98,15 @@ def add_results(self, test): else: raise UnknownResult("%s" % test.result) - def after_test(self): - if self._current_test not in self.results: - self.results.append(self._current_test) + def after_test(self, test): + if test not in self.results: + self.results.append(test) - self.add_results(self._current_test) + self.add_results(test) if not self.options.redirect_logs: self.out.close() self.out = None - self._current_test = None def final_report(self): print "\n" @@ -158,7 +155,7 @@ def final_report(self): self.report() super(XunitReporter, self).final_report() - def _get_captured(self): + def _get_captured(self, test): captured = "" if self.out and not self.options.redirect_logs: self.out.seek(0) @@ -166,11 +163,10 @@ def _get_captured(self): if value: captured += '" @@ -218,7 +214,7 @@ def set_failed(self, test): 'taken': test.time_taken, 'errtype': self._quoteattr(test.result), 'message': self._quoteattr(test.message), - 'systemout': self._get_captured(), + 'systemout': self._get_captured(test), }) def set_passed(self, test): @@ -231,7 +227,7 @@ def set_passed(self, test): {'cls': self._quoteattr(test.get_classname()), 'name': self._quoteattr(test.get_name()), 'taken': test.time_taken, - 'systemout': self._get_captured(), + 'systemout': self._get_captured(test), }) def _forceUnicode(self, s):