summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPreston Holmes <preston@ptone.com>2012-11-16 16:50:50 -0800
committerPreston Holmes <preston@ptone.com>2012-11-16 17:07:38 -0800
commit44046e8a38225067d4d0feac35367eeae133446a (patch)
treed9b3fac853204f1bbd59e9809c8ca65ff481f7b4 /tests
parentb4a98e028adb5b32dcfa7384e46f57b28b43b684 (diff)
Fixed #18985 -- made DeprecationWarnings loud
Capture warnings in Python >= 2.7 and route through console handler, which is subject to DEBUG==True Thanks to dstufft for the idea, and claudep for initial patch
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/logging_tests/tests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py
index 96f81981c6..0e56195c41 100644
--- a/tests/regressiontests/logging_tests/tests.py
+++ b/tests/regressiontests/logging_tests/tests.py
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
import copy
import logging
+import sys
import warnings
from django.conf import compat_patch_logging_config, LazySettings
@@ -10,9 +11,11 @@ from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.utils.log import CallbackFilter, RequireDebugFalse
from django.utils.six import StringIO
+from django.utils.unittest import skipUnless
from ..admin_scripts.tests import AdminScriptTestCase
+PYVERS = sys.version_info[:2]
# logging config prior to using filter with mail_admins
OLD_LOGGING = {
@@ -131,6 +134,32 @@ class DefaultLoggingTest(TestCase):
self.logger.error("Hey, this is an error.")
self.assertEqual(output.getvalue(), 'Hey, this is an error.\n')
+@skipUnless(PYVERS > (2,6), "warnings captured only in Python >= 2.7")
+class WarningLoggerTests(TestCase):
+ """
+ Tests that warnings output for DeprecationWarnings is enabled
+ and captured to the logging system
+ """
+ def setUp(self):
+ self.logger = logging.getLogger('py.warnings')
+ self.old_stream = self.logger.handlers[0].stream
+
+ def tearDown(self):
+ self.logger.handlers[0].stream = self.old_stream
+
+ @override_settings(DEBUG=True)
+ def test_warnings_capture(self):
+ output = StringIO()
+ self.logger.handlers[0].stream = output
+ warnings.warn('Foo Deprecated', DeprecationWarning)
+ self.assertTrue('Foo Deprecated' in output.getvalue())
+
+ def test_warnings_capture_debug_false(self):
+ output = StringIO()
+ self.logger.handlers[0].stream = output
+ warnings.warn('Foo Deprecated', DeprecationWarning)
+ self.assertFalse('Foo Deprecated' in output.getvalue())
+
class CallbackFilterTest(TestCase):
def test_sense(self):