diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-10-15 15:44:33 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-10-15 15:44:33 +0000 |
| commit | 17b8bc69b783be4b81a6c42818c6227845b16683 (patch) | |
| tree | fa481f95e2508b6cf57185cec3e687372fa8ad18 /docs | |
| parent | 083422c0c66c1aa53f9d96c6fd185e238bc51708 (diff) | |
| download | pyramid-17b8bc69b783be4b81a6c42818c6227845b16683.tar.gz pyramid-17b8bc69b783be4b81a6c42818c6227845b16683.tar.bz2 pyramid-17b8bc69b783be4b81a6c42818c6227845b16683.zip | |
Features
--------
- Add ``setUp`` and ``tearDown`` functions to the
``repoze.bfg.testing`` module. Using ``setUp`` in a test setup and
``tearDown`` in a test teardown is now the recommended way to do
component registry setup and teardown. Previously, it was
recommended that a single function named
``repoze.bfg.testing.cleanUp`` be called in both the test setup and
tear down. ``repoze.bfg.testing.cleanUp`` still exists (and will
exist "forever" due to its widespread use); it is now just an alias
for ``repoze.bfg.testing.setUp`` and is nominally deprecated.
- The BFG component registry is now available in view and event
subscriber code as an attribute of the request
ie. ``request.registry``. This fact is currently undocumented
except for this note, because BFG developers never need to interact
with the registry directly anywhere else.
- The BFG component registry now inherits from ``dict``, meaning that
it can optionally be used as a simple dictionary. *Component*
registrations performed against it via e.g. ``registerUtility``,
``registerAdapter``, and similar API methods are kept in a
completely separate namespace than its dict members, so using the
its component API methods won't effect the keys and values in the
dictionary namespace. Likewise, though the component registry
"happens to be" a dictionary, use of mutating dictionary methods
such as ``__setitem__`` will have no influence on any component
registrations made against it. In other words, the registry object
you obtain via e.g. ``repoze.bfg.threadlocal.get_current_registry``
or ``request.registry`` happens to be both a component registry and
a dictionary, but using its component-registry API won't impact data
added to it via its dictionary API and vice versa. This is a
forward compatibility move based on the goals of "marco".
Documentation
-------------
- Various tutorial test modules updated to use
``repoze.bfg.testing.setUp`` and ``repoze.bfg.testing.tearDown``
methods in order to encourage this as best practice going forward.
Backwards Incompatibilities
---------------------------
- Importing ``getSiteManager`` and ``get_registry`` from
``repoze.bfg.registry`` is no longer supported. These imports were
deprecated in repoze.bfg 1.0. Import of ``getSiteManager`` should
be done as ``from zope.component import getSiteManager``. Import of
``get_registry`` should be done as ``from repoze.bfg.threadlocal
import get_current_registry``. This was done to prevent a circular
import dependency.
- Code bases which alternately invoke both
``zope.testing.cleanup.cleanUp`` and ``repoze.bfg.testing.cleanUp``
(treating them equivalently, using them interchangeably) in the
setUp/tearDown of unit tests will begin to experience test failures
due to lack of test isolation. The "right" mechanism is
``repoze.bfg.testing.cleanUp`` (or the combination of
``repoze.bfg.testing.setUp`` and
``repoze.bfg.testing.tearDown``). but a good number of legacy
codebases will use ``zope.testing.cleanup.cleanUp`` instead. We
support ``zope.testing.cleanup.cleanUp`` but not in combination with
``repoze.bfg.testing.cleanUp`` in the same codebase. You should use
one or the other test cleanup function in a single codebase, but not
both.
Internal
--------
- Created new ``repoze.bfg.configuration`` module which assumes
responsibilities previously held by the ``repoze.bfg.registry`` and
``repoze.bfg.router`` modules (avoid a circular import dependency).
- The result of the ``zope.component.getSiteManager`` function in unit
tests set up with ``repoze.bfg.testing.cleanUp`` or
``repoze.bfg.testing.setUp`` will be an instance of
``repoze.bfg.registry.Registry`` instead of the global
``zope.component.globalregistry.base`` registry. This also means
that the threadlocal ZCA API functions such as ``getAdapter`` and
``getUtility`` as well as internal BFG machinery (such as
``model_url`` and ``route_url``) will consult this registry within
unit tests. This is a forward compatibility move based on the goals
of "marco".
- Removed ``repoze.bfg.testing.addCleanUp`` function and associated
module-scope globals. This was never an API.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/api/testing.rst | 4 | ||||
| -rw-r--r-- | docs/narr/unittesting.rst | 13 | ||||
| -rw-r--r-- | docs/tutorials/bfgwiki2/src/authorization/tutorial/tests.py | 12 | ||||
| -rw-r--r-- | docs/tutorials/bfgwiki2/src/views/tutorial/tests.py | 12 |
4 files changed, 35 insertions, 6 deletions
diff --git a/docs/api/testing.rst b/docs/api/testing.rst index f64d78337..94c231459 100644 --- a/docs/api/testing.rst +++ b/docs/api/testing.rst @@ -25,6 +25,10 @@ .. autofunction:: registerRoute + .. autofunction:: setUp + + .. autofunction:: tearDown + .. autofunction:: cleanUp .. autoclass:: DummyModel diff --git a/docs/narr/unittesting.rst b/docs/narr/unittesting.rst index 064be4739..885d7be36 100644 --- a/docs/narr/unittesting.rst +++ b/docs/narr/unittesting.rst @@ -50,10 +50,10 @@ unittest TestCase that used the testing API. class MyTest(unittest.TestCase): def setUp(self): - testing.cleanUp() + testing.setUp() def tearDown(self): - testing.cleanUp() + testing.tearDown() def test_view_fn_not_submitted(self): from my.package import view_fn @@ -105,11 +105,12 @@ assertion. We assert at the end of this that the renderer's ``say`` attribute is ``Yo``, as this is what is expected of the view function in the branch it's testing. -Note that the test calls the ``repoze.bfg.testing.cleanUp`` function -in its ``setUp`` and ``tearDown`` functions. This is required to +Note that the test calls the ``repoze.bfg.testing.setUp`` function in +its ``setUp`` method and the ``repoze.bfg.testing.tearDown`` function +in its ``tearDown`` method. Use of this pattern is required to perform cleanup between the test runs. If you use any of the testing -API, be sure to call this function at setup and teardown of individual -tests. +API, be sure to call ``repoze.bfg.testing.setUp`` in the test setup +and ``repoze.bfg.testing.tearDown`` in the test teardown. See the :ref:`testing_module` chapter for the entire :mod:`repoze.bfg` -specific testing API. This chapter describes APIs for registering a diff --git a/docs/tutorials/bfgwiki2/src/authorization/tutorial/tests.py b/docs/tutorials/bfgwiki2/src/authorization/tutorial/tests.py index 2a1d43749..52d2fed86 100644 --- a/docs/tutorials/bfgwiki2/src/authorization/tutorial/tests.py +++ b/docs/tutorials/bfgwiki2/src/authorization/tutorial/tests.py @@ -17,6 +17,12 @@ def _registerRoutes(): testing.registerRoute('add_page/:pagename', 'add_page') class ViewWikiTests(unittest.TestCase): + def setUp(self): + testing.setUp() + + def tearDown(self): + testing.tearDown() + def test_it(self): from tutorial.views import view_wiki testing.registerRoute(':pagename', 'view_page') @@ -27,9 +33,11 @@ class ViewWikiTests(unittest.TestCase): class ViewPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() + testing.setUp() def tearDown(self): self.session.remove() + testing.tearDown() def _callFUT(self, request): from tutorial.views import view_page @@ -59,9 +67,11 @@ class ViewPageTests(unittest.TestCase): class AddPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() + testing.setUp() def tearDown(self): self.session.remove() + testing.tearDown() def _callFUT(self, request): from tutorial.views import add_page @@ -89,9 +99,11 @@ class AddPageTests(unittest.TestCase): class EditPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() + testing.setUp() def tearDown(self): self.session.remove() + testing.tearDown() def _callFUT(self, request): from tutorial.views import edit_page diff --git a/docs/tutorials/bfgwiki2/src/views/tutorial/tests.py b/docs/tutorials/bfgwiki2/src/views/tutorial/tests.py index 2a1d43749..52d2fed86 100644 --- a/docs/tutorials/bfgwiki2/src/views/tutorial/tests.py +++ b/docs/tutorials/bfgwiki2/src/views/tutorial/tests.py @@ -17,6 +17,12 @@ def _registerRoutes(): testing.registerRoute('add_page/:pagename', 'add_page') class ViewWikiTests(unittest.TestCase): + def setUp(self): + testing.setUp() + + def tearDown(self): + testing.tearDown() + def test_it(self): from tutorial.views import view_wiki testing.registerRoute(':pagename', 'view_page') @@ -27,9 +33,11 @@ class ViewWikiTests(unittest.TestCase): class ViewPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() + testing.setUp() def tearDown(self): self.session.remove() + testing.tearDown() def _callFUT(self, request): from tutorial.views import view_page @@ -59,9 +67,11 @@ class ViewPageTests(unittest.TestCase): class AddPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() + testing.setUp() def tearDown(self): self.session.remove() + testing.tearDown() def _callFUT(self, request): from tutorial.views import add_page @@ -89,9 +99,11 @@ class AddPageTests(unittest.TestCase): class EditPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() + testing.setUp() def tearDown(self): self.session.remove() + testing.tearDown() def _callFUT(self, request): from tutorial.views import edit_page |
