Commits

Michael Foord committed a512027

The TextTestResult now uses runner.message to send messages when used from a TextTestRunner

  • Participants
  • Parent commits c466546
  • Branches plugins

Comments (0)

Files changed (1)

unittest2/runner.py

 
 class _WritelnDecorator(object):
     """Used to decorate file-like objects with a handy 'writeln' method"""
-    def __init__(self,stream):
+    def __init__(self, stream, runner=None):
         self.stream = stream
+        self.runner = runner
 
     def __getattr__(self, attr):
         if attr in ('stream', '__getstate__'):
             raise AttributeError(attr)
         return getattr(self.stream,attr)
+    
+    def writeln(self, arg=None):
+        if self.runner:
+            arg = arg or ''
+            self.runner.message(arg + '\n', (0, 1, 2))
+            return
 
-    def writeln(self, arg=None):
         if arg:
-            self.write(arg)
-        self.write('\n') # text-mode streams translate to \r\n if needed
+            self.stream.write(arg)
+        self.stream.write('\n') # text-mode streams translate to \r\n if needed
 
 
 class TextTestResult(result.TestResult):
 
     def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1,
                     failfast=False, buffer=False, resultclass=None):
-        self.stream = _WritelnDecorator(stream)
+        self.stream = _WritelnDecorator(stream, self)
         
         self.descriptions = descriptions
         if isinstance(verbosity, basestring):
         if event.handled:
             if result:
                 self.stream.write(msg)
+                self.stream.flush()
             return
 
         msg = event.message
                 verb = VERBOSITIES.get(verb, verb)
             if verb == self.verbosity:
                 self.stream.write(msg)
+                self.stream.flush()
                 break
 
     def _makeResult(self):