From 8bbd9b249ed42ed4cd778359afcce696057aa354 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 1 Oct 2015 19:58:20 +0300 Subject: Flush stdout, stderr after every write --- NEWS | 8 ++++++++ yarn | 25 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 2220611..369087b 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,14 @@ NEWS for cmdtest This file summarizes changes between releases of cmdtest. +Version 0.17, released UNRELEASED +--------------------------------- + +* Yarn now flushes outputs (stdout, stderr) whenever it writes + anything. This should avoid some problems with programs that capture + yarn output, such as CI systems, and get the timings differently + from what would happen on a terminal. + Version 0.16, released 2015-06-30 --------------------------------- diff --git a/yarn b/yarn index faa99f6..2df0e8c 100755 --- a/yarn +++ b/yarn @@ -84,23 +84,31 @@ class YarnRunner(cliapp.Application): 'allow scenarios to reference steps that do not exist, ' 'by warning about them, but otherwise ignoring the scenarios') + def stdout(self, msg): + self.output.write(msg) + self.output.flush() + + def stderr(self, msg): + sys.stderr.write(msg) + sys.stderr.flush() + def info(self, indent, msg): if self.settings['verbose']: logging.info(msg) indent_size = 4 - self.output.write('%*s%s\n' % (indent * indent_size, '', msg)) + self.stdout('%*s%s\n' % (indent * indent_size, '', msg)) def warning(self, msg): if self.settings['verbose']: logging.warning(msg) - self.output.write('WARNING: %s\n' % msg) + self.stdout('WARNING: %s\n' % msg) elif not self.settings['quiet']: self.ts.notify('WARNING: %s' % msg) def error(self, msg): if self.settings['verbose']: logging.info(msg) - sys.stderr.write('%s\n' % msg) + self.stderr('%s\n' % msg) elif not self.settings['quiet']: self.ts.error(msg) @@ -157,14 +165,15 @@ class YarnRunner(cliapp.Application): 'Test suite FAILED in %s scenarios' % len(failed_scenarios)) if not self.settings['quiet']: - print ( + self.stdout( 'Scenario test suite PASS, with %d scenarios ' '(%d total steps), ' 'in %.1f seconds' % (self.scenarios_run, self.steps_run, duration)) if self.skipped_for_assuming: - print ('Scenarios SKIPPED due to ASSUMING step failing: %d' - % self.skipped_for_assuming) + self.stdout( + 'Scenarios SKIPPED due to ASSUMING step failing: %d' + % self.skipped_for_assuming) if self.settings['timings']: self.report_timings() @@ -510,9 +519,9 @@ class YarnRunner(cliapp.Application): def report_timings(self): for scenario_name, scenario_duration, step_tuples in self.timings: - print '%5.1f %s' % (scenario_duration, scenario_name) + self.stdout('%5.1f %s' % (scenario_duration, scenario_name)) for step_name, step_duration in step_tuples: - print ' %5.1f %s' % (step_duration, step_name) + self.stdout(' %5.1f %s' % (step_duration, step_name)) YarnRunner(version=cmdtestlib.__version__).run() -- cgit v1.2.1