From 5e99a22964ea4fa42020c822d44a6e534cb30a38 Mon Sep 17 00:00:00 2001 From: Ross Patterson Date: Mon, 12 Mar 2012 11:17:52 -0700 Subject: Use the warnings.catch_warnings context manager in more places. Neither 2.7 nor 2.6 with "setup.py test" or "setup.py nosetests" show warnings that don't already appear for origin/master. FYI, under 2.6 with nosetests I see: nose/loader.py:303: DeprecationWarning: registerView --- pyramid/tests/test_config/test_init.py | 58 ++++++++++++++--------------- pyramid/tests/test_config/test_rendering.py | 37 ++++++++---------- 2 files changed, 43 insertions(+), 52 deletions(-) diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index da331e5ee..37c3de275 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -1,4 +1,5 @@ import unittest +import warnings import os @@ -545,39 +546,33 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(utility, pyramid.tests.test_config) def test_setup_registry_renderer_globals_factory(self): - import warnings - warnings.filterwarnings('ignore') - try: - from pyramid.registry import Registry - from pyramid.interfaces import IRendererGlobalsFactory - reg = Registry() - config = self._makeOne(reg) - factory = object() + from pyramid.registry import Registry + from pyramid.interfaces import IRendererGlobalsFactory + reg = Registry() + config = self._makeOne(reg) + factory = object() + with warnings.catch_warnings(): + warnings.filterwarnings('ignore') config.setup_registry(renderer_globals_factory=factory) - self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None) - config.commit() - utility = reg.getUtility(IRendererGlobalsFactory) - self.assertEqual(utility, factory) - finally: - warnings.resetwarnings() + self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None) + config.commit() + utility = reg.getUtility(IRendererGlobalsFactory) + self.assertEqual(utility, factory) def test_setup_registry_renderer_globals_factory_dottedname(self): - import warnings - warnings.filterwarnings('ignore') - try: - from pyramid.registry import Registry - from pyramid.interfaces import IRendererGlobalsFactory - reg = Registry() - config = self._makeOne(reg) - import pyramid.tests.test_config + from pyramid.registry import Registry + from pyramid.interfaces import IRendererGlobalsFactory + reg = Registry() + config = self._makeOne(reg) + import pyramid.tests.test_config + with warnings.catch_warnings(): + warnings.filterwarnings('ignore') config.setup_registry( renderer_globals_factory='pyramid.tests.test_config') - self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None) - config.commit() - utility = reg.getUtility(IRendererGlobalsFactory) - self.assertEqual(utility, pyramid.tests.test_config) - finally: - warnings.resetwarnings() + self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None) + config.commit() + utility = reg.getUtility(IRendererGlobalsFactory) + self.assertEqual(utility, pyramid.tests.test_config) def test_setup_registry_alternate_renderers(self): from pyramid.registry import Registry @@ -1182,13 +1177,14 @@ pyramid.tests.test_config.dummy_include2""", self.assertTrue(getattr(foo_meth, im_func) is foo) class TestConfiguratorDeprecatedFeatures(unittest.TestCase): + def setUp(self): - import warnings + self.warnings = warnings.catch_warnings() + self.warnings.__enter__() warnings.filterwarnings('ignore') def tearDown(self): - import warnings - warnings.resetwarnings() + self.warnings.__exit__(None, None, None) def _makeOne(self, *arg, **kw): from pyramid.config import Configurator diff --git a/pyramid/tests/test_config/test_rendering.py b/pyramid/tests/test_config/test_rendering.py index 655735511..e6ee9ad70 100644 --- a/pyramid/tests/test_config/test_rendering.py +++ b/pyramid/tests/test_config/test_rendering.py @@ -1,4 +1,5 @@ import unittest +import warnings from pyramid.tests.test_config import dummyfactory @@ -9,32 +10,26 @@ class TestRenderingConfiguratorMixin(unittest.TestCase): return config def test_set_renderer_globals_factory(self): - import warnings - warnings.filterwarnings('ignore') - try: - from pyramid.interfaces import IRendererGlobalsFactory - config = self._makeOne(autocommit=True) - factory = object() + from pyramid.interfaces import IRendererGlobalsFactory + config = self._makeOne(autocommit=True) + factory = object() + with warnings.catch_warnings(): + warnings.filterwarnings('ignore') config.set_renderer_globals_factory(factory) - self.assertEqual( - config.registry.getUtility(IRendererGlobalsFactory), - factory) - finally: - warnings.resetwarnings() + self.assertEqual( + config.registry.getUtility(IRendererGlobalsFactory), + factory) def test_set_renderer_globals_factory_dottedname(self): - import warnings - warnings.filterwarnings('ignore') - try: - from pyramid.interfaces import IRendererGlobalsFactory - config = self._makeOne(autocommit=True) + from pyramid.interfaces import IRendererGlobalsFactory + config = self._makeOne(autocommit=True) + with warnings.catch_warnings(): + warnings.filterwarnings('ignore') config.set_renderer_globals_factory( 'pyramid.tests.test_config.dummyfactory') - self.assertEqual( - config.registry.getUtility(IRendererGlobalsFactory), - dummyfactory) - finally: - warnings.resetwarnings() + self.assertEqual( + config.registry.getUtility(IRendererGlobalsFactory), + dummyfactory) def test_add_renderer(self): from pyramid.interfaces import IRendererFactory -- cgit v1.2.3