From f4dfe65124d87bf4aa59f06ff8cf6e7e3a3ffe15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 19 Feb 2010 13:55:56 +0000
Subject: [PATCH] Following up c31582, this is a way to count errors as errors
 when portal cannot be created and keep readable error messages.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32864 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/tests/ERP5TypeTestCase.py |  4 ++--
 product/ERP5Type/tests/backportUnittest.py | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py
index a3b3267848..13f9f0b17f 100644
--- a/product/ERP5Type/tests/ERP5TypeTestCase.py
+++ b/product/ERP5Type/tests/ERP5TypeTestCase.py
@@ -881,8 +881,8 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase):
       title = self.getTitle()
       from Products.ERP5Type.Base import _aq_reset
       if portal_name in failed_portal_installation:
-        raise backportUnittest.SkipTest('Installation of %s already failed, giving up'
-                              % portal_name)
+        raise backportUnittest.SetupSiteError(
+            'Installation of %s already failed, giving up' % portal_name)
       try:
         if app is None:
           app = ZopeTestCase.app()
diff --git a/product/ERP5Type/tests/backportUnittest.py b/product/ERP5Type/tests/backportUnittest.py
index 3b8d4a6f45..a25e2eb2c3 100644
--- a/product/ERP5Type/tests/backportUnittest.py
+++ b/product/ERP5Type/tests/backportUnittest.py
@@ -35,6 +35,15 @@ class _UnexpectedSuccess(Exception):
   """
   pass
 
+class SetupSiteError(Exception):
+    """
+    The ERP5 Site could not have been setup.
+    This is raised when the site could not have been created in a previous
+    test. We want this to count as an error, but we do not want this to happear
+    in traceback for readability.
+    """
+    pass
+
 def _id(obj):
     return obj
 
@@ -127,6 +136,8 @@ class TestCase(unittest.TestCase):
                 self.setUp()
             except SkipTest, e:
                 result.addSkip(self, str(e))
+            except SetupSiteError, e:
+                result.errors.append(None)
             except Exception:
                 result.addError(self, sys.exc_info())
             else:
@@ -225,6 +236,13 @@ class _TextTestResult(unittest._TextTestResult, TestResult):
             self.stream.write("u")
             self.stream.flush()
 
+    def printErrors(self):
+        if self.dots or self.showAll:
+            self.stream.writeln()
+        # 'None' correspond to redundant errors due to site creation errors,
+        # and we do not display them here.
+        self.printErrorList('ERROR', filter(None, self.errors))
+        self.printErrorList('FAIL', self.failures)
 
 class TextTestRunner(unittest.TextTestRunner):
     def _makeResult(self):
-- 
2.30.9