diff options
| author | Ross Patterson <me@rpatterson.net> | 2012-03-12 10:57:28 -0700 |
|---|---|---|
| committer | Ross Patterson <me@rpatterson.net> | 2012-03-12 10:57:28 -0700 |
| commit | cf95febe026ae347b365bdcc3dc0ddc19a9cb4e8 (patch) | |
| tree | 88ba8b1d700e82692dfbc2ca99ff19bc185cb5c0 | |
| parent | 3b4deef1f6a7825c7c3eb904af15f4d626793b5f (diff) | |
| download | pyramid-cf95febe026ae347b365bdcc3dc0ddc19a9cb4e8.tar.gz pyramid-cf95febe026ae347b365bdcc3dc0ddc19a9cb4e8.tar.bz2 pyramid-cf95febe026ae347b365bdcc3dc0ddc19a9cb4e8.zip | |
Switch to the warnings.catch_warnings context manager for testing.
FYI, this test was failing only under 2.7, not 2.6.
| -rw-r--r-- | pyramid/tests/test_config/test_settings.py | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/pyramid/tests/test_config/test_settings.py b/pyramid/tests/test_config/test_settings.py index 8a385b8ab..0f5239915 100644 --- a/pyramid/tests/test_config/test_settings.py +++ b/pyramid/tests/test_config/test_settings.py @@ -48,20 +48,6 @@ class TestSettingsConfiguratorMixin(unittest.TestCase): self.assertEqual(settings['a'], 1) class TestSettings(unittest.TestCase): - def setUp(self): - self.warnings = [] - import warnings - warnings.old_showwarning = warnings.showwarning - warnings.showwarning = self._showwarning - - def tearDown(self): - del self.warnings - import warnings - warnings.showwarning = warnings.old_showwarning - - def _showwarning(self, message, category, filename, lineno, file=None, - line=None): - self.warnings.append(message) def _getTargetClass(self): from pyramid.config.settings import Settings @@ -74,14 +60,20 @@ class TestSettings(unittest.TestCase): return klass(d, _environ_=environ) def test_getattr_success(self): - settings = self._makeOne({'reload_templates':False}) - self.assertEqual(settings.reload_templates, False) - self.assertEqual(len(self.warnings), 1) + import warnings + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always') + settings = self._makeOne({'reload_templates':False}) + self.assertEqual(settings.reload_templates, False) + self.assertEqual(len(w), 1) def test_getattr_fail(self): - settings = self._makeOne({}) - self.assertRaises(AttributeError, settings.__getattr__, 'wontexist') - self.assertEqual(len(self.warnings), 0) + import warnings + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always') + settings = self._makeOne({}) + self.assertRaises(AttributeError, settings.__getattr__, 'wontexist') + self.assertEqual(len(w), 0) def test_getattr_raises_attribute_error(self): settings = self._makeOne() |
