[Checkins] SVN: zope.tal/trunk/src/zope/tal/ Better test failure reporting in FileTestCase

Marius Gedminas cvs-admin at zope.org
Thu Feb 7 23:04:47 UTC 2013


Log message for revision 129191:
  Better test failure reporting in FileTestCase
  
  Previously the diff would be printed to stdout in the middle of a sea of
  dots, and *then* you'd get test failure assertions mentioning only the
  filename (and on Python 3.3 you'd also get a gratuitous SystemExit
  traceback in addition to the assertion failure)
  
  Now you get a sane single assertion failure with the diff inside it.

Changed:
  U   zope.tal/trunk/src/zope/tal/runtest.py
  U   zope.tal/trunk/src/zope/tal/tests/test_files.py

-=-
Modified: zope.tal/trunk/src/zope/tal/runtest.py
===================================================================
--- zope.tal/trunk/src/zope/tal/runtest.py	2013-02-07 23:04:43 UTC (rev 129190)
+++ zope.tal/trunk/src/zope/tal/runtest.py	2013-02-07 23:04:46 UTC (rev 129191)
@@ -126,7 +126,10 @@
             if not quiet and expected is not None:
                 showdiff(expected, actual)
     if errors:
-        sys.exit(1)
+        if unittesting:
+            return 1
+        else:
+            sys.exit(1)
 
 def readlines(f):
     L = []

Modified: zope.tal/trunk/src/zope/tal/tests/test_files.py
===================================================================
--- zope.tal/trunk/src/zope/tal/tests/test_files.py	2013-02-07 23:04:43 UTC (rev 129190)
+++ zope.tal/trunk/src/zope/tal/tests/test_files.py	2013-02-07 23:04:46 UTC (rev 129191)
@@ -19,6 +19,13 @@
 import sys
 import unittest
 
+try:
+    # Python 2.x
+    from cStringIO import StringIO
+except ImportError:
+    # Python 3.x
+    from io import StringIO
+
 import zope.tal.runtest
 
 from zope.tal.tests import utils
@@ -38,8 +45,6 @@
 
     def runTest(self):
         basename = os.path.basename(self.__file)
-        #sys.stdout.write(basename + " ")
-        sys.stdout.flush()
         if basename.startswith('test_sa'):
             sys.argv = ["", "-Q", "-a", self.__file]
         elif basename.startswith('test_metal'):
@@ -48,14 +53,17 @@
             sys.argv = ["", "-Q", self.__file]
         pwd = os.getcwd()
         try:
-            try:
-                os.chdir(self.__dir)
-                zope.tal.runtest.main()
-            finally:
-                os.chdir(pwd)
-        except SystemExit as what:
-            if what.code:
-                self.fail("output for %s didn't match" % self.__file)
+            os.chdir(self.__dir)
+            old_stdout = sys.stdout
+            sys.stdout = StringIO()
+            failed = zope.tal.runtest.main()
+        finally:
+            captured_stdout = sys.stdout.getvalue()
+            sys.stdout = old_stdout
+            os.chdir(pwd)
+        if failed:
+            self.fail("output for %s didn't match:\n%s"
+                      % (self.__file, captured_stdout))
 
 try:
     script = __file__



More information about the checkins mailing list