Michael Foord avatar Michael Foord committed a512027

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

Comments (0)

Files changed (1)


 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.flush()
         msg = event.message
                 verb = VERBOSITIES.get(verb, verb)
             if verb == self.verbosity:
+                self.stream.flush()
     def _makeResult(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.