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:03:12 -0500 |
| commit | bec250211b0665cfb38b8f2cb6c30a0ca17da7bf (patch) | |
| tree | 8fb10e4d1104cbac101041ce7b2d69f55bfa373f /tests | |
| parent | 9a41045b77c05ea62c49e1bd6f29ebbee7f36954 (diff) | |
[1.5.x] Correctly restore warning capture after logging tests.
This is a fix to the wrong behavior that 15c3906eeb introduced.
Backport of 4befef9 from trunk.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/logging_tests/tests.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py index 35968066bc..080bd03ab6 100644 --- a/tests/regressiontests/logging_tests/tests.py +++ b/tests/regressiontests/logging_tests/tests.py @@ -145,7 +145,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 @@ -164,7 +166,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): |
