[pypy-svn] rev 2614 - pypy/trunk/src/pypy/tool

sschwarzer at codespeak.net sschwarzer at codespeak.net
Sat Dec 20 10:04:34 CET 2003


Author: sschwarzer
Date: Sat Dec 20 10:04:33 2003
New Revision: 2614

Modified:
   pypy/trunk/src/pypy/tool/newtest.py
Log:
Added support for test_runner argument to TestItem.run .


Modified: pypy/trunk/src/pypy/tool/newtest.py
==============================================================================
--- pypy/trunk/src/pypy/tool/newtest.py	(original)
+++ pypy/trunk/src/pypy/tool/newtest.py	Sat Dec 20 10:04:33 2003
@@ -196,7 +196,7 @@
 # provide services from TestCase class also to test functions, e. g.
 # def test_func4711():
 #     service.assertEqual(3, 3.0, msg="objects with same value should be equal")
-#XXX maybe use another name
+#XXX maybe use another name instead of 'service'
 service = TestCase()
 
 #
@@ -332,8 +332,20 @@
         return id(self.module) ^ id(self.cls)
 
     # credit: adapted from Python's unittest.TestCase.run
-    def run(self):
-        """Run this TestItem and return a corresponding TestResult object."""
+    def run(self, test_runner=None):
+        """
+        Run this TestItem and return a corresponding TestResult object.
+        
+        If the test item corresponds to a class method, the setUp and
+        tearDown methods of the associated class are called before and
+        after the invocation of the test method, repectively.
+
+        If the optional argument test_runner is None, the test function
+        or method is merely called with no arguments. Else, test_runner
+        must be a callable accepting one argument. Instead of only calling
+        the test callable, the test_runner object will be called with the
+        test function/method as its argument.
+        """
         if self._isfunction:
             test = self.callable
         else:
@@ -353,7 +365,10 @@
             return Error(msg=str(exc), item=self)
 
         try:
-            test()
+            if test_runner is None:
+                test()
+            else:
+                test_runner(test)
             result = Success(msg='success', item=self)
         except KeyboardInterrupt:
             raise


More information about the Pypy-commit mailing list