summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-01-13 19:02:39 -0500
committerTim Graham <timograham@gmail.com>2016-01-14 09:05:43 -0500
commit5b94b17feff15a9f0345f92fc0568bfe7038e3a3 (patch)
treec1dba0a0e0a3eba2ed687e04187dc4b70cae10a6
parent28acc0d6df844ccfc8de6f4e7d5883eb4841e946 (diff)
Fixed #25999 -- Removed promotion of RemovedInNextVersionWarning to loud by default.
-rw-r--r--django/core/management/commands/test.py16
-rw-r--r--django/utils/log.py13
-rw-r--r--docs/internals/release-process.txt10
-rw-r--r--docs/topics/logging.txt3
-rw-r--r--tests/logging_tests/tests.py31
-rwxr-xr-xtests/runtests.py9
-rw-r--r--tests/test_runner/tests.py28
-rw-r--r--tests/test_runner_deprecation_app/__init__.py0
-rw-r--r--tests/test_runner_deprecation_app/tests.py11
9 files changed, 5 insertions, 116 deletions
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,40 +119,11 @@ 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():
warnings.filterwarnings(
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
--- a/tests/test_runner_deprecation_app/__init__.py
+++ /dev/null
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)