[Zope3-checkins] SVN: zope.testing/trunk/src/zope/testing/testrunner Added logic to cleanup attributes created in test setUp routines.

Jim Fulton jim at zope.com
Fri Dec 2 17:44:17 EST 2005


Log message for revision 40510:
  Added logic to cleanup attributes created in test setUp routines.
  We've found that these attributes sometimes hold resources that can
  be precious.
  

Changed:
  U   zope.testing/trunk/src/zope/testing/testrunner-ex/sampletests/test112.py
  U   zope.testing/trunk/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner-ex/sampletests/test112.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-ex/sampletests/test112.py	2005-12-02 22:44:14 UTC (rev 40509)
+++ zope.testing/trunk/src/zope/testing/testrunner-ex/sampletests/test112.py	2005-12-02 22:44:16 UTC (rev 40510)
@@ -30,6 +30,8 @@
     def setUp(self):
         global x
         x = 1
+        self.clean = getattr(self, 'clean', 0) + 1
+        
     def tearDown(self):
         global x
         x = 0
@@ -46,6 +48,10 @@
         self.assertEqual(samplelayers.layer, layer.layer)
         self.assertEqual(samplelayers.layerx, layer.layerx)
 
+        # This is a test that the test runner clears attributes
+        # that are set in setUp but not cleared in tearDown.
+        self.assertEqual(self.clean, 1)
+
 class TestB(unittest.TestCase):
     layer = layername
 

Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py	2005-12-02 22:44:14 UTC (rev 40509)
+++ zope.testing/trunk/src/zope/testing/testrunner.py	2005-12-02 22:44:16 UTC (rev 40510)
@@ -436,7 +436,10 @@
         if options.post_mortem:
             # post-mortem debugging
             for test in tests:
+                if result.shouldStop:
+                    break
                 result.startTest(test)
+                state = test.__dict__.copy()
                 try:
                     try:
                         test.debug()
@@ -449,11 +452,19 @@
                         result.addSuccess(test)
                 finally:
                     result.stopTest(test)
+                test.__dict__.clear()
+                test.__dict__.update(state)
 
         else:
             # normal
-            tests(result)
-
+            for test in tests:
+                if result.shouldStop:
+                    break
+                state = test.__dict__.copy()
+                test(result)
+                test.__dict__.clear()
+                test.__dict__.update(state)
+ 
         t = time.time() - t
         if options.verbose == 1 or options.progress:
             result.stopTests()



More information about the Zope3-Checkins mailing list