Skip to content
Browse files

Correctly restore warning capture after logging tests.

This is a fix to the wrong behavior that 15c3906 introduced.
  • Loading branch information...
1 parent 35cab0f commit 4befef91f17cd082f387caaa8871c5852cd4c9ce @jacobian jacobian committed
Showing with 4 additions and 2 deletions.
  1. +4 −2 tests/logging_tests/
6 tests/logging_tests/
@@ -96,7 +96,9 @@ def setUp(self):
# If tests are invoke with "-Wall" (or any -W flag actually) then
# warning logging gets disabled (see django/conf/ However,
# these tests expect warnings to be logged, so manually force warnings
- # to the logs.
+ # to the logs. Use getattr() here because the logging capture state is
+ # undocumented and (I assume) brittle.
+ self._old_capture_state = bool(getattr(logging, '_warnings_showwarning', False))
# this convoluted setup is to avoid printing this deprecation to
@@ -115,7 +117,7 @@ def tearDown(self):
self.logger.handlers[i].stream = self.old_streams[i]
# Reset warnings state.
- logging.captureWarnings(False)
+ logging.captureWarnings(self._old_capture_state)
def test_warnings_capture(self):

0 comments on commit 4befef9

Please sign in to comment.
Something went wrong with that request. Please try again.