diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-11-28 19:27:47 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-11-28 19:27:47 +0000 |
| commit | 7ac5aa82a7e67cd82744976315b93a9d660f9ad3 (patch) | |
| tree | 0284b99022ecf74be7f45c4ae2fb25b6cff3a7ec | |
| parent | fe399b8d88746fda216a66bf80f6185ddf0fbac2 (diff) | |
| download | pyramid-7ac5aa82a7e67cd82744976315b93a9d660f9ad3.tar.gz pyramid-7ac5aa82a7e67cd82744976315b93a9d660f9ad3.tar.bz2 pyramid-7ac5aa82a7e67cd82744976315b93a9d660f9ad3.zip | |
Deal with registries we may not understand.
| -rw-r--r-- | repoze/bfg/testing.py | 8 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_testing.py | 17 |
2 files changed, 23 insertions, 2 deletions
diff --git a/repoze/bfg/testing.py b/repoze/bfg/testing.py index 1859cf9b8..9cba616a7 100644 --- a/repoze/bfg/testing.py +++ b/repoze/bfg/testing.py @@ -531,7 +531,7 @@ def setUp(registry=None, request=None, hook_zca=True): .. note:: The ``setUp`` function is new as of :mod:`repoze.bfg` 1.1. - Use this function in the ``setUp`` method of a unit test test case + Use this function in the ``setUp`` method of a unittest test case which directly or indirectly uses: - any of the ``register*`` functions in ``repoze.bfg.testing`` @@ -621,7 +621,11 @@ def tearDown(unhook_zca=True): if info is not None: reg = info['registry'] if hasattr(reg, '__init__') and hasattr(reg, '__name__'): - reg.__init__(reg.__name__) + try: + reg.__init__(reg.__name__) + except TypeError: + # maybe somebody's using a registry we don't understand + pass _clearContext() # XXX why? def cleanUp(*arg, **kw): diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py index 6341825ef..0a9da3e85 100644 --- a/repoze/bfg/tests/test_testing.py +++ b/repoze/bfg/tests/test_testing.py @@ -614,6 +614,23 @@ class Test_tearDown(unittest.TestCase): getSiteManager.reset() manager.clear() + def test_registry_cannot_be_inited(self): + from repoze.bfg.threadlocal import manager + registry = DummyRegistry() + def raiseit(name): + raise TypeError + registry.__init__ = raiseit + old = {'registry':registry} + hook = lambda *arg: None + try: + manager.push(old) + self._callFUT() # doesn't blow up + current = manager.get() + self.assertNotEqual(current, old) + self.assertEqual(registry.inited, 1) + finally: + manager.clear() + def test_unhook_zc_false(self): from repoze.bfg.threadlocal import manager from zope.component import getSiteManager |
