[Checkins] SVN: zope.testrunner/trunk/ Make StartUpFailure compatible with unittest.TextTestRunner().

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


Log message for revision 129167:
  Make StartUpFailure compatible with unittest.TextTestRunner().
  
  Fixes https://bugs.launchpad.net/zope.testrunner/+bug/1118344
  
  

Changed:
  U   zope.testrunner/trunk/CHANGES.txt
  U   zope.testrunner/trunk/src/zope/testrunner/find.py

-=-
Modified: zope.testrunner/trunk/CHANGES.txt
===================================================================
--- zope.testrunner/trunk/CHANGES.txt	2013-02-07 12:44:24 UTC (rev 129166)
+++ zope.testrunner/trunk/CHANGES.txt	2013-02-07 13:13:04 UTC (rev 129167)
@@ -9,6 +9,9 @@
 
 - Dropped support for Python 2.4 and 2.5.
 
+- Made StartUpFailure compatible with unittest.TextTestRunner() (LP #1118344).
+
+
 4.0.4 (2011-10-25)
 ==================
 

Modified: zope.testrunner/trunk/src/zope/testrunner/find.py
===================================================================
--- zope.testrunner/trunk/src/zope/testrunner/find.py	2013-02-07 12:44:24 UTC (rev 129166)
+++ zope.testrunner/trunk/src/zope/testrunner/find.py	2013-02-07 13:13:04 UTC (rev 129167)
@@ -44,22 +44,43 @@
     >>> s.shortDescription()
     'StartUpFailure: import errors in fauxmodule.'
 
-    However, if the post mortem option is enabled:
+    Sometimes test suited collected by zope.testrunner end up being run
+    by a regular unittest TestRunner, and it's not hard to make sure
+    StartUpFailure does something sensible in that case
 
-    >>> options.post_mortem = True
+    >>> r = unittest.TestResult(sys.stdout)
+    >>> s.run(r)
+    >>> print r.failures[0][1], # doctest: +ELLIPSIS
+    Traceback (most recent call last):
+      ...
+    AssertionError: could not import fauxmodule
 
-    ...then the the StartUpFailure will start the debugger and stop
-    the test run after the debugger quits.
-    
-    To simulate this, we need an exception and its associated
-    exc_info: 
+    If you'd like more details, be sure to pass the original exc_info::
 
     >>> import sys
     >>> try:
-    ...    raise Exception()
+    ...    raise Exception('something bad happened during import')
     ... except:
     ...     exc_info = sys.exc_info()
 
+    >>> s = StartUpFailure(options, 'fauxmodule', exc_info)
+
+    >>> r = unittest.TestResult(sys.stdout)
+    >>> s.run(r)
+    >>> print r.errors[0][0].shortDescription()
+    StartUpFailure: import errors in fauxmodule.
+    >>> print r.errors[0][1], # doctest: +ELLIPSIS
+    Traceback (most recent call last):
+      ...
+    Exception: something bad happened during import
+
+    However, if the post mortem option is enabled:
+
+    >>> options.post_mortem = True
+
+    ...then the the StartUpFailure will start the debugger and stop
+    the test run after the debugger quits.
+
     To simulate the user pressing 'c' and hitting return in the
     debugger, we use a FakeInputContinueGenerator:
     
@@ -82,7 +103,7 @@
     ...   sys.stdin = old_stdin
     Result:
     ...Exception:
-    <BLANKLINE>
+    something bad happened during import
     ...
     (Pdb) c
     <BLANKLINE>
@@ -112,6 +133,7 @@
             zope.testrunner.debug.post_mortem(exc_info)
         self.module = module
         self.exc_info = exc_info
+        super(StartUpFailure, self).__init__()
 
     def shortDescription(self):
         return 'StartUpFailure: import errors in %s.' % self.module
@@ -119,7 +141,13 @@
     def __repr__(self):
         return '<StartUpFailure module=%s>' % self.module
 
+    def runTest(self):
+        if self.exc_info is None or any(x is None for x in self.exc_info):
+            self.fail("could not import %s" % self.module)
+        else:
+            raise self.exc_info[0], self.exc_info[1], self.exc_info[2]
 
+
 def find_tests(options, found_suites=None):
     """Creates a dictionary mapping layer name to a suite of tests to be run
     in that layer.



More information about the checkins mailing list