diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2013-03-27 17:01:11 -0500 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2013-03-27 17:01:11 -0500 |
| commit | 4befef91f17cd082f387caaa8871c5852cd4c9ce (patch) | |
| tree | 442c2163e22415dc31aab11983308d1c325adcc1 /tests | |
| parent | 35cab0f8e43c01a7d5ede4ebc96e5e8723a04338 (diff) | |
Correctly restore warning capture after logging tests.
This is a fix to the wrong behavior that 15c3906eeb introduced.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/logging_tests/tests.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 84e4319273..27ae651042 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -96,7 +96,9 @@ class WarningLoggerTests(TestCase): # If tests are invoke with "-Wall" (or any -W flag actually) then # warning logging gets disabled (see django/conf/__init__.py). 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)) logging.captureWarnings(True) # this convoluted setup is to avoid printing this deprecation to @@ -115,7 +117,7 @@ class WarningLoggerTests(TestCase): self.logger.handlers[i].stream = self.old_streams[i] # Reset warnings state. - logging.captureWarnings(False) + logging.captureWarnings(self._old_capture_state) @override_settings(DEBUG=True) def test_warnings_capture(self): |
