Kaydet (Commit) ade98599 authored tarafından Tim Graham's avatar Tim Graham

Fixed #24095 -- Prevented WarningLoggerTests from leaking a warnings filter.

üst 862ea825
...@@ -101,7 +101,6 @@ class WarningLoggerTests(TestCase): ...@@ -101,7 +101,6 @@ class WarningLoggerTests(TestCase):
# undocumented and (I assume) brittle. # undocumented and (I assume) brittle.
self._old_capture_state = bool(getattr(logging, '_warnings_showwarning', False)) self._old_capture_state = bool(getattr(logging, '_warnings_showwarning', False))
logging.captureWarnings(True) logging.captureWarnings(True)
warnings.filterwarnings('always')
# this convoluted setup is to avoid printing this deprecation to # this convoluted setup is to avoid printing this deprecation to
# stderr during test running - as the test runner forces deprecations # stderr during test running - as the test runner forces deprecations
...@@ -123,14 +122,18 @@ class WarningLoggerTests(TestCase): ...@@ -123,14 +122,18 @@ class WarningLoggerTests(TestCase):
@override_settings(DEBUG=True) @override_settings(DEBUG=True)
def test_warnings_capture(self): def test_warnings_capture(self):
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning) with warnings.catch_warnings():
output = force_text(self.outputs[0].getvalue()) warnings.filterwarnings('always')
self.assertIn('Foo Deprecated', output) warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertIn('Foo Deprecated', output)
def test_warnings_capture_debug_false(self): def test_warnings_capture_debug_false(self):
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning) with warnings.catch_warnings():
output = force_text(self.outputs[0].getvalue()) warnings.filterwarnings('always')
self.assertNotIn('Foo Deprecated', output) warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertNotIn('Foo Deprecated', output)
@override_settings(DEBUG=True) @override_settings(DEBUG=True)
def test_error_filter_still_raises(self): def test_error_filter_still_raises(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment