Avoided changing raw DeprecationWarning filter behavior

Refs #21188. Now pure Python DeprecationWarning visibility should
be back to Python defaults.
This commit is contained in:
Claude Paroz 2014-03-08 11:13:45 +01:00
parent 210d0489c5
commit 0c6a339952
5 changed files with 19 additions and 11 deletions

View File

@ -10,6 +10,9 @@ class RemovedInDjango18Warning(DeprecationWarning):
pass pass
RemovedInNextVersionWarning = RemovedInDjango18Warning
class warn_about_renamed_method(object): class warn_about_renamed_method(object):
def __init__(self, class_name, old_method_name, new_method_name, deprecation_warning): def __init__(self, class_name, old_method_name, new_method_name, deprecation_warning):
self.class_name = class_name self.class_name = class_name

View File

@ -5,6 +5,7 @@ import warnings
from django.conf import settings from django.conf import settings
from django.core import mail from django.core import mail
from django.core.mail import get_connection from django.core.mail import get_connection
from django.utils.deprecation import RemovedInNextVersionWarning
from django.utils.module_loading import import_string from django.utils.module_loading import import_string
from django.views.debug import ExceptionReporter, get_exception_reporter_filter from django.views.debug import ExceptionReporter, get_exception_reporter_filter
@ -68,8 +69,9 @@ def configure_logging(logging_config, logging_settings):
if not sys.warnoptions: if not sys.warnoptions:
# Route warnings through python logging # Route warnings through python logging
logging.captureWarnings(True) logging.captureWarnings(True)
# Allow DeprecationWarnings through the warnings filters # RemovedInNextVersionWarning is a subclass of DeprecationWarning which
warnings.simplefilter("default", DeprecationWarning) # is hidden by default, hence we force the "default" behavior
warnings.simplefilter("default", RemovedInNextVersionWarning)
if logging_config: if logging_config:
# First find the logging configuration function ... # First find the logging configuration function ...

View File

@ -7,6 +7,7 @@ from django.core import mail
from django.test import TestCase, RequestFactory, override_settings from django.test import TestCase, RequestFactory, override_settings
from django.test.utils import patch_logger from django.test.utils import patch_logger
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.deprecation import RemovedInNextVersionWarning
from django.utils.log import (CallbackFilter, RequireDebugFalse, from django.utils.log import (CallbackFilter, RequireDebugFalse,
RequireDebugTrue) RequireDebugTrue)
from django.utils.six import StringIO from django.utils.six import StringIO
@ -86,8 +87,8 @@ class DefaultLoggingTest(TestCase):
class WarningLoggerTests(TestCase): class WarningLoggerTests(TestCase):
""" """
Tests that warnings output for DeprecationWarnings is enabled Tests that warnings output for RemovedInDjangoXXWarning (XX being the next
and captured to the logging system Django version) is enabled and captured to the logging system
""" """
def setUp(self): def setUp(self):
# If tests are invoke with "-Wall" (or any -W flag actually) then # If tests are invoke with "-Wall" (or any -W flag actually) then
@ -118,12 +119,12 @@ class WarningLoggerTests(TestCase):
@override_settings(DEBUG=True) @override_settings(DEBUG=True)
def test_warnings_capture(self): def test_warnings_capture(self):
warnings.warn('Foo Deprecated', DeprecationWarning) warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue()) output = force_text(self.outputs[0].getvalue())
self.assertTrue('Foo Deprecated' in output) self.assertTrue('Foo Deprecated' in output)
def test_warnings_capture_debug_false(self): def test_warnings_capture_debug_false(self):
warnings.warn('Foo Deprecated', DeprecationWarning) warnings.warn('Foo Deprecated', RemovedInNextVersionWarning)
output = force_text(self.outputs[0].getvalue()) output = force_text(self.outputs[0].getvalue())
self.assertFalse('Foo Deprecated' in output) self.assertFalse('Foo Deprecated' in output)

View File

@ -13,6 +13,7 @@ from django import db
from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature
from django.test.testcases import connections_support_transactions from django.test.testcases import connections_support_transactions
from django.test.utils import IgnoreAllDeprecationWarningsMixin, override_system_checks from django.test.utils import IgnoreAllDeprecationWarningsMixin, override_system_checks
from django.utils import six
from admin_scripts.tests import AdminScriptTestCase from admin_scripts.tests import AdminScriptTestCase
from .models import Person from .models import Person
@ -368,14 +369,14 @@ class DeprecationDisplayTest(AdminScriptTestCase):
args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app'] args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertIn("Ran 1 test", err) self.assertIn("Ran 1 test", err)
self.assertIn("DeprecationWarning: warning from test", err) six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: warning from test")
self.assertIn("DeprecationWarning: module-level warning from deprecation_app", err) six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: module-level warning from deprecation_app")
def test_runner_deprecation_verbosity_zero(self): def test_runner_deprecation_verbosity_zero(self):
args = ['test', '--settings=test_project.settings', '--verbosity=0', 'test_runner_deprecation_app'] args = ['test', '--settings=test_project.settings', '--verbosity=0', 'test_runner_deprecation_app']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertIn("Ran 1 test", err) self.assertIn("Ran 1 test", err)
self.assertFalse("DeprecationWarning: warning from test" in err) self.assertFalse("warning from test" in err)
class AutoIncrementResetTest(TransactionTestCase): class AutoIncrementResetTest(TransactionTestCase):

View File

@ -1,10 +1,11 @@
import warnings import warnings
from django.test import TestCase from django.test import TestCase
from django.utils.deprecation import RemovedInNextVersionWarning
warnings.warn("module-level warning from deprecation_app", DeprecationWarning) warnings.warn("module-level warning from deprecation_app", RemovedInNextVersionWarning)
class DummyTest(TestCase): class DummyTest(TestCase):
def test_warn(self): def test_warn(self):
warnings.warn("warning from test", DeprecationWarning) warnings.warn("warning from test", RemovedInNextVersionWarning)