[Checkins] SVN: z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/ allow_teardown is now overridable in the register_all_tests() call.

Reinout van Rees reinout at vanrees.org
Mon Aug 31 10:14:55 EDT 2009


Log message for revision 103401:
  allow_teardown is now overridable in the register_all_tests() call.
  It is also respected in functional/doctesting.py now.

Changed:
  U   z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/doctesting.py
  U   z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/functional/doctesting.py
  U   z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/testrunner.txt
  U   z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/README_OLD.txt
  A   z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/cave/samplesetup_teardown.py

-=-
Modified: z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/doctesting.py
===================================================================
--- z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/doctesting.py	2009-08-31 14:02:08 UTC (rev 103400)
+++ z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/doctesting.py	2009-08-31 14:14:55 UTC (rev 103401)
@@ -33,7 +33,8 @@
     encoding = 'utf-8'
 
     def __init__(self, package, setup=None, teardown=None, globs=None,
-                 optionflags=None, encoding=None, **kw):
+                 optionflags=None, encoding=None,
+                 allow_teardown=True, **kw):
         BasicTestSetup.__init__(self, package, **kw)
         self.setUp = setup or self.setUp
         self.tearDown = teardown or self.tearDown
@@ -42,6 +43,7 @@
             self.globs = globs
         if optionflags is not None:
             self.optionflags = optionflags
+        self.allow_teardown = allow_teardown
 
 
 class SimpleDocTestSetup(DocTestSetup):
@@ -128,7 +130,7 @@
             DefaultZCMLLayer.__module__,
             '%s [%s]' % (DefaultZCMLLayer.__name__,
                          os.path.join(os.path.dirname(filepath), zcml_file)),
-            allow_teardown=True)
+            allow_teardown=self.allow_teardown)
         return layer
 
     def isTestFile(self, filepath):

Modified: z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/functional/doctesting.py
===================================================================
--- z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/functional/doctesting.py	2009-08-31 14:02:08 UTC (rev 103400)
+++ z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/functional/doctesting.py	2009-08-31 14:14:55 UTC (rev 103401)
@@ -55,8 +55,10 @@
     checker = None
 
     def __init__(self, package, checker=None, zcml_config = None,
-                 layer_name='FunctionalLayer', layer=None, **kw):
+                 layer_name='FunctionalLayer', layer=None,
+                 allow_teardown=True, **kw):
         DocTestSetup.__init__(self, package, **kw)
+        self.allow_teardown = allow_teardown
         self.checker = checker
         # Setup a new layer if specified in params...
         if zcml_config is not None and layer is None:
@@ -65,20 +67,22 @@
                     os.path.dirname(self.package.__file__),
                     zcml_config)
             self.layer = ZCMLLayer(zcml_config, self.package.__name__,
-                                   layer_name)
+                                   layer_name,
+                                   allow_teardown=self.allow_teardown)
         elif layer is None:
             # Look for ftesting.zcml in pkg-root...
             pkg_ftesting_zcml = os.path.join(
                 os.path.dirname(self.package.__file__), 'ftesting.zcml')
             if os.path.isfile(pkg_ftesting_zcml):
                 self.layer = ZCMLLayer(pkg_ftesting_zcml,
-                                       self.package.__name__, layer_name)
+                                       self.package.__name__, layer_name,
+                                       allow_teardown=self.allow_teardown)
         # Passing a ready-for-use layer overrides layer specified by
         # zcml_config...
         if layer is not None:
             self.layer = layer
         return
-        
+
     def setUp(self, test):
         FunctionalTestSetup().setUp()
 

Modified: z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/testrunner.txt
===================================================================
--- z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/testrunner.txt	2009-08-31 14:02:08 UTC (rev 103400)
+++ z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/testrunner.txt	2009-08-31 14:14:55 UTC (rev 103401)
@@ -50,8 +50,6 @@
 Of the four tests apparently run, there is one 'normal' python test
 and three doctests, of which two are functional doctests.
 
-TODO for Reinout: test with functionallayers WITH the "not supported" message.
-
 Now, we only want to run the doctests in the ``cave`` package. A
 suitable setup is contained in `samplesetup_short1.py`` in the
 ``cave`` package::
@@ -189,16 +187,45 @@
       Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
     Running zope.testing.testrunner.layer.UnitTests tests:
       Tear down z3c.testsetup.tests.cave.SampleLayer ...
-      Running in a subprocess.
       Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
       Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+    Tearing down left over layers:
       Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
     Total: 4 tests, 0 failures, 0 errors in N.NNN seconds.
     False
 
 Apparently now the custom ZCML file in the ``cave`` package was used.
 
+We can add an allow_teardown=False option, this prevents the test mechanism
+from tearing down the functional layers, they're run in a separate process
+instead:
 
+    >>> setupfile = os.path.join(cavepath, 'samplesetup_teardown.py')
+    >>> print open(setupfile).read()
+    import z3c.testsetup
+    test_suite = z3c.testsetup.register_all_tests(
+        'z3c.testsetup.tests.cave',
+        zcml_config='sampleftesting.zcml',
+        layer_name = 'SampleLayer',
+        allow_teardown=False)
+    >>> defaults = [
+    ...     '--path', cavepath,
+    ...     '--tests-pattern', '^samplesetup_teardown$',
+    ...     ]
+    >>> testrunner.run(defaults)
+    Running z3c.testsetup.tests.cave.SampleLayer tests:
+      Set up z3c.testsetup.tests.cave.SampleLayer in N.NNN seconds.
+      Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+    Running zope.testing.testrunner.layer.UnitTests tests:
+      Tear down z3c.testsetup.tests.cave.SampleLayer ...
+      Running in a subprocess.
+      Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+      Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+      Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+    Total: 4 tests, 0 failures, 0 errors in N.NNN seconds.
+    False
+
+
 Setting output checker for functional tests
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Modified: z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/README_OLD.txt
===================================================================
--- z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/README_OLD.txt	2009-08-31 14:02:08 UTC (rev 103400)
+++ z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/README_OLD.txt	2009-08-31 14:14:55 UTC (rev 103401)
@@ -81,7 +81,8 @@
    register_all_tests(pkg_or_dotted_name, filter_func, extensions,
                       encoding, checker,
                       globs, setup, teardown, optionflags
-                      zcml_config, layer_name, layer)
+                      zcml_config, layer_name, layer,
+                      allow_teardown)
 
 where all but the first parameter are keyword paramters and all but
 the package parameter are optional.
@@ -438,7 +439,15 @@
     This parameter overrides any ``zcml_config`` and ``layer_name``
     parameter.
 
+- **allow_teardown**:
 
+    True by default.  This allows the testing mechanism to try to tear down
+    ZCML layers.  If set to False, every ZCML layer is run in a separate
+    process for really complete isolation.  Setting it to False leads to
+    incomplete profiling and code coverage data.  It needs to be set to False
+    in rare cases like setting interfaces on classes programmatically.
+
+
 How to mark testfiles/modules
 =============================
 

Added: z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/cave/samplesetup_teardown.py
===================================================================
--- z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/cave/samplesetup_teardown.py	                        (rev 0)
+++ z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/cave/samplesetup_teardown.py	2009-08-31 14:14:55 UTC (rev 103401)
@@ -0,0 +1,6 @@
+import z3c.testsetup
+test_suite = z3c.testsetup.register_all_tests(
+    'z3c.testsetup.tests.cave',
+    zcml_config='sampleftesting.zcml',
+    layer_name = 'SampleLayer',
+    allow_teardown=False)


Property changes on: z3c.testsetup/branches/reinout-teardown/src/z3c/testsetup/tests/cave/samplesetup_teardown.py
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the checkins mailing list