Prevented calling setup() inside catch_warnings

When django.setup() (and then configure_logging) is called inside
catch_warnings, logging setup is negatively affected (notably
warnings.showwarning definition).
This commit is contained in:
Claude Paroz 2014-01-01 22:55:50 +01:00
parent 1386075f62
commit b2d78939d1
2 changed files with 8 additions and 5 deletions

View File

@ -91,8 +91,8 @@ class WarningLoggerTests(TestCase):
""" """
def setUp(self): def setUp(self):
# If tests are invoke with "-Wall" (or any -W flag actually) then # If tests are invoke with "-Wall" (or any -W flag actually) then
# warning logging gets disabled (see django/conf/__init__.py). However, # warning logging gets disabled (see configure_logging in django/utils/log.py).
# these tests expect warnings to be logged, so manually force warnings # However, these tests expect warnings to be logged, so manually force warnings
# to the logs. Use getattr() here because the logging capture state is # to the logs. Use getattr() here because the logging capture state is
# undocumented and (I assume) brittle. # undocumented and (I assume) brittle.
self._old_capture_state = bool(getattr(logging, '_warnings_showwarning', False)) self._old_capture_state = bool(getattr(logging, '_warnings_showwarning', False))

View File

@ -125,10 +125,13 @@ def setup(verbosity, test_labels):
handler = logging.StreamHandler() handler = logging.StreamHandler()
logger.addHandler(handler) logger.addHandler(handler)
warnings.filterwarnings(
'ignore',
'django.contrib.comments is deprecated and will be removed before Django 1.8.',
DeprecationWarning
)
# Load all the ALWAYS_INSTALLED_APPS. # Load all the ALWAYS_INSTALLED_APPS.
with warnings.catch_warnings(): django.setup()
warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', DeprecationWarning)
django.setup()
# Load all the test model apps. # Load all the test model apps.
test_modules = get_test_modules() test_modules = get_test_modules()