From 5b94b17feff15a9f0345f92fc0568bfe7038e3a3 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 13 Jan 2016 19:02:39 -0500 Subject: [PATCH] Fixed #25999 -- Removed promotion of RemovedInNextVersionWarning to loud by default. --- django/core/management/commands/test.py | 16 ---------- django/utils/log.py | 13 -------- docs/internals/release-process.txt | 10 +++--- docs/topics/logging.txt | 3 -- tests/logging_tests/tests.py | 31 ------------------- tests/runtests.py | 9 ------ tests/test_runner/tests.py | 28 ----------------- tests/test_runner_deprecation_app/__init__.py | 0 tests/test_runner_deprecation_app/tests.py | 11 ------- 9 files changed, 5 insertions(+), 116 deletions(-) delete mode 100644 tests/test_runner_deprecation_app/__init__.py delete mode 100644 tests/test_runner_deprecation_app/tests.py diff --git a/django/core/management/commands/test.py b/django/core/management/commands/test.py index 6fdaca944c..b02c105261 100644 --- a/django/core/management/commands/test.py +++ b/django/core/management/commands/test.py @@ -1,4 +1,3 @@ -import logging import os import sys @@ -54,21 +53,6 @@ class Command(BaseCommand): if hasattr(test_runner_class, 'add_arguments'): test_runner_class.add_arguments(parser) - def execute(self, *args, **options): - if options['verbosity'] > 0: - # ensure that deprecation warnings are displayed during testing - # the following state is assumed: - # logging.capturewarnings is true - # a "default" level warnings filter has been added for - # DeprecationWarning. See django.conf.LazySettings._configure_logging - logger = logging.getLogger('py.warnings') - handler = logging.StreamHandler() - logger.addHandler(handler) - super(Command, self).execute(*args, **options) - if options['verbosity'] > 0: - # remove the testing-specific handler - logger.removeHandler(handler) - def handle(self, *test_labels, **options): from django.conf import settings from django.test.utils import get_runner diff --git a/django/utils/log.py b/django/utils/log.py index fcc7575180..cc15dfa636 100644 --- a/django/utils/log.py +++ b/django/utils/log.py @@ -2,15 +2,12 @@ from __future__ import unicode_literals import logging import logging.config # needed when logging_config doesn't start with logging.config -import sys -import warnings from copy import copy from django.conf import settings from django.core import mail from django.core.mail import get_connection from django.core.management.color import color_style -from django.utils.deprecation import RemovedInNextVersionWarning from django.utils.module_loading import import_string from django.views.debug import ExceptionReporter @@ -62,21 +59,11 @@ DEFAULT_LOGGING = { 'level': 'INFO', 'propagate': False, }, - 'py.warnings': { - 'handlers': ['console'], - }, } } def configure_logging(logging_config, logging_settings): - if not sys.warnoptions: - # Route warnings through python logging - logging.captureWarnings(True) - # 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 ... logging_config_func = import_string(logging_config) diff --git a/docs/internals/release-process.txt b/docs/internals/release-process.txt index 7ca2e452a5..2c05f909d9 100644 --- a/docs/internals/release-process.txt +++ b/docs/internals/release-process.txt @@ -92,16 +92,16 @@ So, for example, if we decided to start the deprecation of a function in Django 4.2: * Django 4.2 will contain a backwards-compatible replica of the function which - will raise a ``RemovedInDjango51Warning``. This warning is silent by - default; you can turn on display of these warnings with the ``-Wd`` option - of Python. + will raise a ``RemovedInDjango51Warning``. * Django 5.0 (the version that follows 4.2) will still contain the - backwards-compatible replica. This warning becomes *loud* by default and - will likely be quite annoying. + backwards-compatible replica. * Django 5.1 will remove the feature outright. +The warnings are silent by default. You can turn on display of these warnings +with the ``python -Wd`` option. + A more generic example: * X.0 diff --git a/docs/topics/logging.txt b/docs/topics/logging.txt index 407f12aaef..9cb1da45b4 100644 --- a/docs/topics/logging.txt +++ b/docs/topics/logging.txt @@ -739,9 +739,6 @@ When :setting:`DEBUG` is ``True``: * The ``django`` catch-all logger sends all messages at the ``INFO`` level or higher to the console. -* The ``py.warnings`` logger, which handles messages from ``warnings.warn()``, - sends messages to the console. - When :setting:`DEBUG` is ``False``: * The ``django`` logger send messages with ``ERROR`` or ``CRITICAL`` level to diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 6cba5942b1..8864786f28 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -12,12 +12,10 @@ from django.core.files.temp import NamedTemporaryFile from django.test import RequestFactory, SimpleTestCase, override_settings from django.test.utils import LoggingCaptureMixin, patch_logger from django.utils.deprecation import RemovedInNextVersionWarning -from django.utils.encoding import force_text from django.utils.log import ( DEFAULT_LOGGING, AdminEmailHandler, CallbackFilter, RequireDebugFalse, RequireDebugTrue, ) -from django.utils.six import StringIO from .logconfig import MyEmailBackend @@ -121,39 +119,10 @@ class WarningLoggerTests(SimpleTestCase): self._old_capture_state = bool(getattr(logging, '_warnings_showwarning', False)) logging.captureWarnings(True) - # this convoluted setup is to avoid printing this deprecation to - # stderr during test running - as the test runner forces deprecations - # to be displayed at the global py.warnings level - self.logger = logging.getLogger('py.warnings') - self.outputs = [] - self.old_streams = [] - for handler in self.logger.handlers: - self.old_streams.append(handler.stream) - self.outputs.append(StringIO()) - handler.stream = self.outputs[-1] - def tearDown(self): - for i, handler in enumerate(self.logger.handlers): - self.logger.handlers[i].stream = self.old_streams[i] - # Reset warnings state. logging.captureWarnings(self._old_capture_state) - @override_settings(DEBUG=True) - def test_warnings_capture(self): - with warnings.catch_warnings(): - warnings.filterwarnings('always') - warnings.warn('Foo Deprecated', RemovedInNextVersionWarning) - output = force_text(self.outputs[0].getvalue()) - self.assertIn('Foo Deprecated', output) - - def test_warnings_capture_debug_false(self): - with warnings.catch_warnings(): - warnings.filterwarnings('always') - warnings.warn('Foo Deprecated', RemovedInNextVersionWarning) - output = force_text(self.outputs[0].getvalue()) - self.assertNotIn('Foo Deprecated', output) - @override_settings(DEBUG=True) def test_error_filter_still_raises(self): with warnings.catch_warnings(): diff --git a/tests/runtests.py b/tests/runtests.py index 76e1ba4406..b819262d9e 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import atexit import copy -import logging import os import shutil import subprocess @@ -162,14 +161,6 @@ def setup(verbosity, test_labels, parallel): log_config['loggers']['django']['level'] = 'ERROR' settings.LOGGING = log_config - if verbosity > 0: - # Ensure any warnings captured to logging are piped through a verbose - # logging handler. If any -W options were passed explicitly on command - # line, warnings are not captured, and this has no effect. - logger = logging.getLogger('py.warnings') - handler = logging.StreamHandler() - logger.addHandler(handler) - warnings.filterwarnings( 'ignore', 'The GeoManager class is deprecated.', diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index e3f4a8f4b6..8a8332093d 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -16,8 +16,6 @@ from django.test import ( ) from django.test.runner import DiscoverRunner, dependency_ordered from django.test.testcases import connections_support_transactions -from django.utils import six -from django.utils.encoding import force_text from .models import Person @@ -337,32 +335,6 @@ class SetupDatabasesTests(unittest.TestCase): ) -class DeprecationDisplayTest(AdminScriptTestCase): - # tests for 19546 - def setUp(self): - settings = { - 'DATABASES': '{"default": {"ENGINE":"django.db.backends.sqlite3", "NAME":":memory:"}}' - } - self.write_settings('settings.py', sdict=settings) - - def tearDown(self): - self.remove_settings('settings.py') - - def test_runner_deprecation_verbosity_default(self): - args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app'] - out, err = self.run_django_admin(args) - self.assertIn("Ran 1 test", force_text(err)) - # change "NextVersion" to "RemovedInDjango\d+" in Django 1.11. - six.assertRegex(self, err, r"RemovedInNextVersionWarning: warning from test") - six.assertRegex(self, err, r"RemovedInNextVersionWarning: 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.assertNotIn("warning from test", err) - - class AutoIncrementResetTest(TransactionTestCase): """ Here we test creating the same model two times in different test methods, diff --git a/tests/test_runner_deprecation_app/__init__.py b/tests/test_runner_deprecation_app/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/test_runner_deprecation_app/tests.py b/tests/test_runner_deprecation_app/tests.py deleted file mode 100644 index 22925736fc..0000000000 --- a/tests/test_runner_deprecation_app/tests.py +++ /dev/null @@ -1,11 +0,0 @@ -import warnings - -from django.test import TestCase -from django.utils.deprecation import RemovedInNextVersionWarning - -warnings.warn("module-level warning from deprecation_app", RemovedInNextVersionWarning) - - -class DummyTest(TestCase): - def test_warn(self): - warnings.warn("warning from test", RemovedInNextVersionWarning)