Commits

Kumar McMillan committed a4c53cc

case.shortDescription() is more forgiving to __str__ errors (issue 422)

Comments (0)

Files changed (3)

         # 2.7 compat: shortDescription() always returns something
         # which is a change from 2.6 and below, and breaks the
         # testName plugin call.
-        desc = self.test.shortDescription()
-        if desc == str(self.test):
-            return
+        try:
+            desc = self.test.shortDescription()
+        except Exception:
+            # this is probably caused by a problem in test.__str__() and is
+            # only triggered by python 3.1's unittest!
+            pass
+        try:
+            if desc == str(self.test):
+                return
+        except Exception:
+            # If str() triggers an exception then ignore it.
+            # see issue 422
+            pass
         return desc
 
 
 .SH COPYRIGHT
 LGPL
 
-.\" Generated by docutils manpage writer on 2011-05-02 15:26.
+.\" Generated by docutils manpage writer on 2011-05-27 09:59.
 .\" 

unit_tests/test_cases.py

         assert case_c.shortDescription() in (None, # pre 2.7
                                              'test_c (test_cases.TC)') # 2.7
 
+    def test_unrepresentable_shortDescription(self):
+        class TC(unittest.TestCase):
+            def __str__(self):
+                # see issue 422
+                raise ValueError('simulate some mistake in this code')
+            def runTest(self):
+                pass
+
+        case = nose.case.Test(TC())
+        self.assertEqual(case.shortDescription(), None)
+
 if __name__ == '__main__':
     unittest.main()