Avoided changing raw DeprecationWarning filter behavior
Refs #21188. Now pure Python DeprecationWarning visibility should be back to Python defaults.
This commit is contained in:
parent
210d0489c5
commit
0c6a339952
|
@ -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
|
||||
|
|
|
@ -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 ...
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue