[Zope-Checkins] SVN: Zope/trunk/ Collector #1445: Fixed bad interaction between -p and -v(v) options to test.py that resulted in exceptions being printed when they shouldn't have been.

Chris Withers chris at simplistix.co.uk
Fri Jul 30 17:10:03 EDT 2004


Log message for revision 26861:
  Collector #1445: Fixed bad interaction between -p and -v(v) options to test.py that resulted in exceptions being printed when they shouldn't have been.
  


Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/test.py


-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2004-07-30 21:04:10 UTC (rev 26860)
+++ Zope/trunk/doc/CHANGES.txt	2004-07-30 21:10:03 UTC (rev 26861)
@@ -139,6 +139,10 @@
 
     Bugs fixed
 
+     - Collector #1445: Fixed bad interaction between -p and -v(v)
+       options to test.py that resulted in exceptions being printed
+       when they shouldn't have been.
+
      - Collector #729: manage_main doesn't display the correct page title
        most of the time. It is not completely fixed but using title_or_id
        makes folders display the correct id as a fallback.

Modified: Zope/trunk/test.py
===================================================================
--- Zope/trunk/test.py	2004-07-30 21:04:10 UTC (rev 26860)
+++ Zope/trunk/test.py	2004-07-30 21:10:03 UTC (rev 26861)
@@ -254,16 +254,32 @@
         for i in range(n):
             print >>stream, "%6dms" % int(results[i][1] * 1000), results[i][0]
 
-    def _print_traceback(self, msg, err, test, errlist):
-        if self.showAll or self.dots or self._progress:
-            self.stream.writeln("\n")
+    def _handle_problem(self, err, test, errlist):
+        
+        if self._debug:
+            raise err[0], err[1], err[2]
+        
+        if errlist is self.errors:
+            prefix = 'Error'
+        else:
+            prefix = 'Failure'
+            
+        tb = "".join(traceback.format_exception(*err))
+        
+        if self._progress:
+            self.stream.writeln("\r")
+            self.stream.writeln("%s in test %s" % (prefix,test))
+            self.stream.writeln(tb)
             self._lastWidth = 0
+        elif self.showAll:
+            self._lastWidth = 0
+            self.stream.writeln(prefix.upper())
+        elif self.dots:
+            self.stream.write(prefix[0])
+            
+        if not self._progress:
+            errlist.append((test, tb))
 
-        tb = "".join(traceback.format_exception(*err))
-        self.stream.writeln(msg)
-        self.stream.writeln(tb)
-        errlist.append((test, tb))
-
     def startTest(self, test):
         if self._progress:
             self.stream.write("\r%4d" % (self.testsRun + 1))
@@ -300,20 +316,10 @@
         return s[:self._maxWidth]
 
     def addError(self, test, err):
-        if self._progress:
-            self.stream.write("\r")
-        if self._debug:
-            raise err[0], err[1], err[2]
-        self._print_traceback("Error in test %s" % test, err,
-                              test, self.errors)
+        self._handle_problem(err, test, self.errors)
 
     def addFailure(self, test, err):
-        if self._progress:
-            self.stream.write("\r")
-        if self._debug:
-            raise err[0], err[1], err[2]
-        self._print_traceback("Failure in test %s" % test, err,
-                              test, self.failures)
+        self._handle_problem(err, test, self.failures)
 
     def printErrors(self):
         if self._progress and not (self.dots or self.showAll):



More information about the Zope-Checkins mailing list