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

sschwarzer at codespeak.net sschwarzer at codespeak.net
Fri Dec 19 14:11:17 CET 2003


Author: sschwarzer
Date: Fri Dec 19 14:11:16 2003
New Revision: 2559

Modified:
   pypy/trunk/src/pypy/tool/newtest.py
Log:
Addition for last commit: Added a method 'run' to TestSuite class. This one
runs all tests at once.
Remedied subtle problems by using an import statement before executing the
function main and qualifying main as newtest.main .


Modified: pypy/trunk/src/pypy/tool/newtest.py
==============================================================================
--- pypy/trunk/src/pypy/tool/newtest.py	(original)
+++ pypy/trunk/src/pypy/tool/newtest.py	Fri Dec 19 14:11:16 2003
@@ -253,10 +253,6 @@
 
         # credit: adapted from Python's unittest.TestCase.run
 
-        # make sure that TestResult classes refer to the same objects
-        # as in test modules importing this module
-        from pypy.tool import newtest
-
         testobject = self.cls()
         testmethod = getattr(testobject, self.method.__name__)
 
@@ -267,22 +263,22 @@
                 testobject.setUp()
             except KeyboardInterrupt:
                 raise
-            except newtest.TestResult, result:
+            except TestResult, result:
                 # reconstruct TestResult object, implicitly set exception
                 result = result.__class__(msg=result.msg, item=self)
             except Exception, exc:
-                return newtest.Error(msg=str(exc), item=self)
+                return Error(msg=str(exc), item=self)
 
             try:
                 testmethod()
-                result = newtest.Success(msg='success', item=self)
+                result = Success(msg='success', item=self)
             except KeyboardInterrupt:
                 raise
-            except newtest.TestResult, result:
+            except TestResult, result:
                 # reconstruct TestResult object, implicitly set exception
                 result = result.__class__(msg=result.msg, item=self)
             except Exception, exc:
-                result = newtest.Error(msg=str(exc), item=self)
+                result = Error(msg=str(exc), item=self)
 
             try:
                 testobject.tearDown()
@@ -292,7 +288,7 @@
                 # if we already had an exception in the test method,
                 # don't overwrite it
                 if result.traceback is None:
-                    result = newtest.Error(msg=str(exc), item=self)
+                    result = Error(msg=str(exc), item=self)
         finally:
             if posttest is not None:
                 posttest(self)
@@ -335,7 +331,7 @@
         items = []
         # scan the module for classes derived from TestCase
         for obj in vars(module).values():
-            if inspect.isclass(obj) and issubclass(obj, newtest.TestCase):
+            if inspect.isclass(obj) and issubclass(obj, TestCase):
                 # we found a TestCase class, now scan it for test methods
                 for obj2 in vars(obj).values():
                     # inspect.ismethod doesn't seem to work here
@@ -445,4 +441,7 @@
 
 
 if __name__ == '__main__':
-    main(do_selftest=True)
+    # used to avoid subtle problems with class matching after different
+    # import statements
+    from pypy.tool import newtest
+    newtest.main(do_selftest=True)


More information about the Pypy-commit mailing list