[py-svn] r12260 - in py/dist/py: documentation/example/pytest test test/terminal

hpk at codespeak.net hpk at codespeak.net
Sat May 14 12:41:30 CEST 2005


Author: hpk
Date: Sat May 14 12:41:29 2005
New Revision: 12260

Added:
   py/dist/py/documentation/example/pytest/test_failures.py
Modified:
   py/dist/py/test/collect.py
   py/dist/py/test/terminal/terminal.py
Log:
fix problem with reporting the (looked-ahead) 
number of testitems for a module.  If an exception
occurs while determining the number of test items 
then the reporter will report '?' as the number of
testitems. 



Added: py/dist/py/documentation/example/pytest/test_failures.py
==============================================================================
--- (empty file)
+++ py/dist/py/documentation/example/pytest/test_failures.py	Sat May 14 12:41:29 2005
@@ -0,0 +1,12 @@
+
+import py
+failure_demo = py.magic.autopath().dirpath('failure_demo.py')
+
+def test_failure_demo_fails_properly(): 
+    config, args = py.test.Config.parse([]) 
+    session = config.getsessionclass()(config, py.std.sys.stdout)
+    session.main([failure_demo]) 
+    l = session.getitemoutcomepairs(py.test.Item.Failed)
+    assert len(l) == 21 
+    l = session.getitemoutcomepairs(py.test.Item.Passed)
+    assert not l 

Modified: py/dist/py/test/collect.py
==============================================================================
--- py/dist/py/test/collect.py	(original)
+++ py/dist/py/test/collect.py	Sat May 14 12:41:29 2005
@@ -183,7 +183,16 @@
 
     def _prepare(self): 
         if not hasattr(self, '_name2items'): 
-            self._name2items = self.buildname2items()
+            ex = getattr(self, '_name2items_exception', None)
+            if ex is not None: 
+                raise ex[0], ex[1], ex[2]
+            try: 
+                self._name2items = self.buildname2items()
+            except (SystemExit, KeyboardInterrupt): 
+                raise 
+            except:
+                self._name2items_exception = py.std.sys.exc_info()
+                raise 
 
     def buildname2items(self): 
         raise NotImplementedError, "abstract" 

Modified: py/dist/py/test/terminal/terminal.py
==============================================================================
--- py/dist/py/test/terminal/terminal.py	(original)
+++ py/dist/py/test/terminal/terminal.py	Sat May 14 12:41:29 2005
@@ -64,10 +64,16 @@
     def startiteration(self, colitem, subitems): 
         if (isinstance(colitem, py.test.collect.Module) 
             and self.config.option.verbose == 0): 
-            sum = 0
-            for sub in subitems: 
-                sum += len(list(colitem.join(sub).tryiter()))
-            self.out.write('[%d] ' % sum) 
+            try: 
+                sum = 0
+                for sub in subitems: 
+                    sum += len(list(colitem.join(sub).tryiter()))
+            except (SystemExit, KeyboardInterrupt): 
+                raise 
+            except: 
+                self.out.write('[?]')
+            else: 
+                self.out.write('[%d] ' % sum) 
             return self.out.line 
 
     def start_Item(self, colitem): 



More information about the pytest-commit mailing list