Skip to content

Commit

Permalink
Fixed #24095 -- Prevented WarningLoggerTests from leaking a warnings …
Browse files Browse the repository at this point in the history
…filter.
  • Loading branch information
timgraham committed Jan 8, 2015
1 parent 862ea82 commit ade9859
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/logging_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def setUp(self):
# undocumented and (I assume) brittle.
self._old_capture_state = bool(getattr(logging, '_warnings_showwarning', False))
logging.captureWarnings(True)
warnings.filterwarnings('always')

# this convoluted setup is to avoid printing this deprecation to
# stderr during test running - as the test runner forces deprecations
Expand All @@ -123,14 +122,18 @@ def tearDown(self):

@override_settings(DEBUG=True)
def test_warnings_capture(self):
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertIn('Foo Deprecated', output)
with warnings.catch_warnings():
warnings.filterwarnings('always')
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertIn('Foo Deprecated', output)

def test_warnings_capture_debug_false(self):
warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue())
self.assertNotIn('Foo Deprecated', 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):
Expand Down

0 comments on commit ade9859

Please sign in to comment.