[Checkins] SVN: zope.pytest/trunk/ Switch from session-scope to function-scope for proper test separation on configuration.

Ulrich Fouquet cvs-admin at zope.org
Mon May 28 11:48:29 UTC 2012


Log message for revision 126507:
  Switch from session-scope to function-scope for proper test separation on configuration.

Changed:
  U   zope.pytest/trunk/CHANGES.txt
  U   zope.pytest/trunk/src/zope/pytest/setup.py
  A   zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/ftesting2.zcml
  U   zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/tests/test_foo.py

-=-
Modified: zope.pytest/trunk/CHANGES.txt
===================================================================
--- zope.pytest/trunk/CHANGES.txt	2012-05-28 11:45:58 UTC (rev 126506)
+++ zope.pytest/trunk/CHANGES.txt	2012-05-28 11:48:26 UTC (rev 126507)
@@ -4,7 +4,11 @@
 0.2 (unreleased)
 ================
 
-- No changes yet.
+- Changed scope of `configure` from 'session' to 'function'. This
+  guarantees proper test separation (ZCML registrations done in one
+  test will not show up in another test). Drawback is that single
+  tests are more expensive in setup/teardown resulting in longer test
+  runs.
 
 0.1 (2011-03-05)
 ================

Modified: zope.pytest/trunk/src/zope/pytest/setup.py
===================================================================
--- zope.pytest/trunk/src/zope/pytest/setup.py	2012-05-28 11:45:58 UTC (rev 126506)
+++ zope.pytest/trunk/src/zope/pytest/setup.py	2012-05-28 11:48:26 UTC (rev 126507)
@@ -112,7 +112,7 @@
 
     return request.cached_setup(setup=setup_function,
                                 teardown=teardown_config,
-                                scope='session')
+                                scope='function')
 
 def setup_config(package, zcml_file):
     """Setup a configuration.

Added: zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/ftesting2.zcml
===================================================================
--- zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/ftesting2.zcml	                        (rev 0)
+++ zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/ftesting2.zcml	2012-05-28 11:48:26 UTC (rev 126507)
@@ -0,0 +1,11 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   package="mypkg2"
+   >
+
+  <include package="zope.component" file="meta.zcml" />
+  <utility component=".app.FooUtility"
+	   provides=".interfaces.IFoo"
+	   name="baz" />
+
+</configure>

Modified: zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/tests/test_foo.py
===================================================================
--- zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/tests/test_foo.py	2012-05-28 11:45:58 UTC (rev 126506)
+++ zope.pytest/trunk/src/zope/pytest/tests/sample_fixtures/zcml/mypkg2/tests/test_foo.py	2012-05-28 11:48:26 UTC (rev 126507)
@@ -3,13 +3,41 @@
 from mypkg2.interfaces import IFoo
 from zope.pytest import configure
 
-def pytest_funcarg__config_mypkg2(request):
+def pytest_funcarg__config_ftesting(request):
+    # register components in 'ftesting.zcml'
     return configure(request, mypkg2, 'ftesting.zcml')
 
-def test_get_utility(config_mypkg2):
+def pytest_funcarg__config_ftesting2(request):
+    # register components in 'ftesting2.zcml'
+    return configure(request, mypkg2, 'ftesting2.zcml')
+
+
+def test_get_utility(config_ftesting):
+    # we can get a utility registered in 'ftesting.zcml'
     util = queryUtility(IFoo, name='foo utility', default=None)
     assert util is not None
 
-def test_dofoo_utility(config_mypkg2):
+def test_dofoo_utility(config_ftesting):
     util = queryUtility(IFoo, name='foo utility', default=None)
     assert util().do_foo() == 'Foo!'
+
+
+# The following tests are 'numbered', so we can be sure they are run
+# in this very order. They should prove proper test separation
+# regarding ZCML registrations.
+def test_zcml_separation0(config_ftesting):
+    # the utilites from ftesting.zcml are available in this test (and
+    # the ones from ftesting2.zcml are not)
+    util1 = queryUtility(IFoo, name='baz', default=None)
+    util2 = queryUtility(IFoo, name='foo utility', default=None)
+    assert util1 is None
+    assert util2 is not None
+
+def test_zcml_separation1(config_ftesting2):
+    # the utilites from ftesting2.zcml are available in this test (and
+    # the ones from ftesting.zcml are not, although they were
+    # registered in the previous test.
+    util1 = queryUtility(IFoo, name='baz', default=None)
+    util2 = queryUtility(IFoo, name='foo utility', default=None)
+    assert util1 is not None
+    assert util2 is None



More information about the checkins mailing list