diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index b00c8d5..051ab70 100644
|
a
|
b
|
a list of all possible variables.
|
| 8 | 8 | |
| 9 | 9 | import logging |
| 10 | 10 | import os |
| | 11 | import sys |
| 11 | 12 | import time # Needed for Windows |
| 12 | 13 | import warnings |
| 13 | 14 | |
| … |
… |
class LazySettings(LazyObject):
|
| 56 | 57 | """ |
| 57 | 58 | Setup logging from LOGGING_CONFIG and LOGGING settings. |
| 58 | 59 | """ |
| 59 | | try: |
| 60 | | # Route warnings through python logging |
| 61 | | logging.captureWarnings(True) |
| 62 | | # Allow DeprecationWarnings through the warnings filters |
| 63 | | warnings.simplefilter("default", DeprecationWarning) |
| 64 | | except AttributeError: |
| 65 | | # No captureWarnings on Python 2.6, DeprecationWarnings are on anyway |
| 66 | | pass |
| | 60 | if not sys.warnoptions: |
| | 61 | try: |
| | 62 | # Route warnings through python logging |
| | 63 | logging.captureWarnings(True) |
| | 64 | # Allow DeprecationWarnings through the warnings filters |
| | 65 | warnings.simplefilter("default", DeprecationWarning) |
| | 66 | except AttributeError: |
| | 67 | # No captureWarnings on Python 2.6, DeprecationWarnings are on anyway |
| | 68 | pass |
| 67 | 69 | |
| 68 | 70 | if self.LOGGING_CONFIG: |
| 69 | 71 | from django.utils.log import DEFAULT_LOGGING |
diff --git a/django/core/management/commands/test.py b/django/core/management/commands/test.py
index 48b330a..2b8e801 100644
|
a
|
b
|
|
| | 1 | import logging |
| 1 | 2 | import sys |
| 2 | 3 | import os |
| 3 | 4 | from optparse import make_option, OptionParser |
| … |
… |
from django.conf import settings
|
| 6 | 7 | from django.core.management.base import BaseCommand |
| 7 | 8 | from django.test.utils import get_runner |
| 8 | 9 | |
| | 10 | |
| 9 | 11 | class Command(BaseCommand): |
| 10 | 12 | option_list = BaseCommand.option_list + ( |
| 11 | 13 | make_option('--noinput', |
| … |
… |
class Command(BaseCommand):
|
| 57 | 59 | version=self.get_version(), |
| 58 | 60 | option_list=options) |
| 59 | 61 | |
| | 62 | def execute(self, *args, **options): |
| | 63 | if int(options['verbosity']) > 0: |
| | 64 | # ensure that deprecation warnings are displayed during testing |
| | 65 | # the following state is assumed: |
| | 66 | # logging.capturewarnings is true |
| | 67 | # a "default" level warnings filter has been added for |
| | 68 | # DeprecationWarning. See django.conf.LazySettings._configure_logging |
| | 69 | logger = logging.getLogger('py.warnings') |
| | 70 | handler = logging.StreamHandler() |
| | 71 | logger.addHandler(handler) |
| | 72 | super(Command, self).execute(*args, **options) |
| | 73 | if int(options['verbosity']) > 0: |
| | 74 | # remove the testing-specific handler |
| | 75 | logger.removeHandler(handler) |
| | 76 | |
| 60 | 77 | def handle(self, *test_labels, **options): |
| 61 | 78 | from django.conf import settings |
| 62 | 79 | from django.test.utils import get_runner |
diff --git a/django/test/simple.py b/django/test/simple.py
index 8faf1e4..bf0219d 100644
|
a
|
b
|
|
| 1 | | import logging |
| 2 | 1 | import unittest as real_unittest |
| 3 | 2 | |
| 4 | 3 | from django.conf import settings |
| … |
… |
class DjangoTestSuiteRunner(object):
|
| 366 | 365 | self.setup_test_environment() |
| 367 | 366 | suite = self.build_suite(test_labels, extra_tests) |
| 368 | 367 | old_config = self.setup_databases() |
| 369 | | if self.verbosity > 0: |
| 370 | | # ensure that deprecation warnings are displayed during testing |
| 371 | | # the following state is assumed: |
| 372 | | # logging.capturewarnings is true |
| 373 | | # a "default" level warnings filter has been added for |
| 374 | | # DeprecationWarning. See django.conf.LazySettings._configure_logging |
| 375 | | logger = logging.getLogger('py.warnings') |
| 376 | | handler = logging.StreamHandler() |
| 377 | | logger.addHandler(handler) |
| 378 | 368 | result = self.run_suite(suite) |
| 379 | | if self.verbosity > 0: |
| 380 | | # remove the testing-specific handler |
| 381 | | logger.removeHandler(handler) |
| 382 | 369 | self.teardown_databases(old_config) |
| 383 | 370 | self.teardown_test_environment() |
| 384 | 371 | return self.suite_result(suite, result) |
diff --git a/tests/regressiontests/test_runner/deprecation_app/tests.py b/tests/regressiontests/test_runner/deprecation_app/tests.py
index e676c3e..6dee088 100644
|
a
|
b
|
import warnings
|
| 2 | 2 | |
| 3 | 3 | from django.test import TestCase |
| 4 | 4 | |
| | 5 | warnings.warn("module-level warning from deprecation_app", DeprecationWarning) |
| | 6 | |
| 5 | 7 | class DummyTest(TestCase): |
| 6 | 8 | def test_warn(self): |
| 7 | 9 | warnings.warn("warning from test", DeprecationWarning) |
diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
index 5df421c..b5e4a1d 100644
|
a
|
b
|
class DeprecationDisplayTest(AdminScriptTestCase):
|
| 298 | 298 | def test_runner_deprecation_verbosity_default(self): |
| 299 | 299 | args = ['test', '--settings=regressiontests.settings'] |
| 300 | 300 | out, err = self.run_django_admin(args) |
| 301 | | self.assertTrue("DeprecationWarning: warning from test" in err) |
| | 301 | self.assertIn("DeprecationWarning: warning from test", err) |
| | 302 | self.assertIn("DeprecationWarning: module-level warning from deprecation_app", err) |
| 302 | 303 | |
| 303 | 304 | @unittest.skipIf(sys.version_info[:2] == (2, 6), |
| 304 | 305 | "On Python 2.6, DeprecationWarnings are visible anyway") |
diff --git a/tests/runtests.py b/tests/runtests.py
index 8c56e27..90dc0f5 100755
|
a
|
b
|
|
| 1 | 1 | #!/usr/bin/env python |
| | 2 | import logging |
| 2 | 3 | import os |
| 3 | 4 | import shutil |
| 4 | 5 | import subprocess |
| … |
… |
def setup(verbosity, test_labels):
|
| 106 | 107 | # in our tests. |
| 107 | 108 | settings.MANAGERS = ("admin@djangoproject.com",) |
| 108 | 109 | |
| | 110 | if verbosity > 0: |
| | 111 | # Ensure py.warnings are piped through a verbose logging handler |
| | 112 | logger = logging.getLogger('py.warnings') |
| | 113 | handler = logging.StreamHandler() |
| | 114 | logger.addHandler(handler) |
| | 115 | |
| 109 | 116 | # Load all the ALWAYS_INSTALLED_APPS. |
| 110 | 117 | # (This import statement is intentionally delayed until after we |
| 111 | 118 | # access settings because of the USE_I18N dependency.) |