Loading django/core/management/commands/test.py +0 −16 Original line number Diff line number Diff line import logging import os import sys Loading Loading @@ -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 Loading django/utils/log.py +0 −13 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) Loading docs/internals/release-process.txt +5 −5 Original line number Diff line number Diff line Loading @@ -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 Loading docs/topics/logging.txt +0 −3 Original line number Diff line number Diff line Loading @@ -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 Loading tests/logging_tests/tests.py +0 −31 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(): Loading Loading
django/core/management/commands/test.py +0 −16 Original line number Diff line number Diff line import logging import os import sys Loading Loading @@ -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 Loading
django/utils/log.py +0 −13 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) Loading
docs/internals/release-process.txt +5 −5 Original line number Diff line number Diff line Loading @@ -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 Loading
docs/topics/logging.txt +0 −3 Original line number Diff line number Diff line Loading @@ -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 Loading
tests/logging_tests/tests.py +0 −31 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(): Loading