[1.7.x] Fixed #24095 -- Prevented WarningLoggerTests from leaking a warnings filter.

Backport of ade9859996 from master
This commit is contained in:
Tim Graham 2015-01-07 18:49:02 -05:00
parent 5e18f6f724
commit 557c514f90
1 changed files with 10 additions and 6 deletions

View File

@ -120,14 +120,18 @@ class WarningLoggerTests(TestCase):
@override_settings(DEBUG=True)
def test_warnings_capture(self):
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertTrue('Foo Deprecated' in output)
with warnings.catch_warnings():
warnings.filterwarnings('always')
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertTrue('Foo Deprecated' in output)
def test_warnings_capture_debug_false(self):
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertFalse('Foo Deprecated' in output)
with warnings.catch_warnings():
warnings.filterwarnings('always')
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertNotIn('Foo Deprecated', output)
@override_settings(DEBUG=True)
def test_error_filter_still_raises(self):