diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py index a4f928e73b..a9a1dcfbe2 100644 --- a/django/utils/deprecation.py +++ b/django/utils/deprecation.py @@ -10,6 +10,9 @@ class RemovedInDjango18Warning(DeprecationWarning): pass +RemovedInNextVersionWarning = RemovedInDjango18Warning + + class warn_about_renamed_method(object): def __init__(self, class_name, old_method_name, new_method_name, deprecation_warning): self.class_name = class_name diff --git a/django/utils/log.py b/django/utils/log.py index f319704116..83ba15f52a 100644 --- a/django/utils/log.py +++ b/django/utils/log.py @@ -5,6 +5,7 @@ import warnings from django.conf import settings from django.core import mail from django.core.mail import get_connection +from django.utils.deprecation import RemovedInNextVersionWarning from django.utils.module_loading import import_string 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: # Route warnings through python logging logging.captureWarnings(True) - # Allow DeprecationWarnings through the warnings filters - warnings.simplefilter("default", DeprecationWarning) + # RemovedInNextVersionWarning is a subclass of DeprecationWarning which + # is hidden by default, hence we force the "default" behavior + warnings.simplefilter("default", RemovedInNextVersionWarning) if logging_config: # First find the logging configuration function ... diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 4140608f57..8aff4ec6c4 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -7,6 +7,7 @@ from django.core import mail from django.test import TestCase, RequestFactory, override_settings from django.test.utils import patch_logger from django.utils.encoding import force_text +from django.utils.deprecation import RemovedInNextVersionWarning from django.utils.log import (CallbackFilter, RequireDebugFalse, RequireDebugTrue) from django.utils.six import StringIO @@ -86,8 +87,8 @@ class DefaultLoggingTest(TestCase): class WarningLoggerTests(TestCase): """ - Tests that warnings output for DeprecationWarnings is enabled - and captured to the logging system + Tests that warnings output for RemovedInDjangoXXWarning (XX being the next + Django version) is enabled and captured to the logging system """ def setUp(self): # If tests are invoke with "-Wall" (or any -W flag actually) then @@ -118,12 +119,12 @@ class WarningLoggerTests(TestCase): @override_settings(DEBUG=True) def test_warnings_capture(self): - warnings.warn('Foo Deprecated', DeprecationWarning) + warnings.warn('Foo Deprecated', RemovedInNextVersionWarning) output = force_text(self.outputs[0].getvalue()) self.assertTrue('Foo Deprecated' in output) def test_warnings_capture_debug_false(self): - warnings.warn('Foo Deprecated', DeprecationWarning) + warnings.warn('Foo Deprecated', RemovedInNextVersionWarning) output = force_text(self.outputs[0].getvalue()) self.assertFalse('Foo Deprecated' in output) diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index 80a2cb8e54..3bc89bf2ab 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -13,6 +13,7 @@ from django import db from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature from django.test.testcases import connections_support_transactions from django.test.utils import IgnoreAllDeprecationWarningsMixin, override_system_checks +from django.utils import six from admin_scripts.tests import AdminScriptTestCase from .models import Person @@ -368,14 +369,14 @@ class DeprecationDisplayTest(AdminScriptTestCase): args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app'] out, err = self.run_django_admin(args) self.assertIn("Ran 1 test", err) - self.assertIn("DeprecationWarning: warning from test", err) - self.assertIn("DeprecationWarning: module-level warning from deprecation_app", err) + six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: warning from test") + six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: module-level warning from deprecation_app") def test_runner_deprecation_verbosity_zero(self): args = ['test', '--settings=test_project.settings', '--verbosity=0', 'test_runner_deprecation_app'] out, err = self.run_django_admin(args) self.assertIn("Ran 1 test", err) - self.assertFalse("DeprecationWarning: warning from test" in err) + self.assertFalse("warning from test" in err) class AutoIncrementResetTest(TransactionTestCase): diff --git a/tests/test_runner_deprecation_app/tests.py b/tests/test_runner_deprecation_app/tests.py index 0d947c35c2..22925736fc 100644 --- a/tests/test_runner_deprecation_app/tests.py +++ b/tests/test_runner_deprecation_app/tests.py @@ -1,10 +1,11 @@ import warnings 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): def test_warn(self): - warnings.warn("warning from test", DeprecationWarning) + warnings.warn("warning from test", RemovedInNextVersionWarning)