summaryrefslogtreecommitdiff
path: root/tests/logging_tests
diff options
context:
space:
mode:
authorFrançois Freitag <mail@franek.fr>2020-05-07 21:06:09 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-08 10:49:34 +0200
commit01f8d19ef95af7087f9480372fc9c2a124be2842 (patch)
treef0ff482cf0945d3e37587767ab794d2643a33445 /tests/logging_tests
parentfc0f7f6c152766c92a95c74a02cc6fab79440ed8 (diff)
Fixed tests isolation in logging_tests.
The SetupConfigureLogging test case does not restore the logging config after its execution. It leaves the logger django.request with an empty handlers array. This also removes the last use of LOGGING_CONFIG, introduced in 43503b093a35ca4707c16d865f10929960bfa0b8.
Diffstat (limited to 'tests/logging_tests')
-rw-r--r--tests/logging_tests/tests.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py
index c2e26d5102..e565905795 100644
--- a/tests/logging_tests/tests.py
+++ b/tests/logging_tests/tests.py
@@ -21,25 +21,6 @@ from django.views.debug import ExceptionReporter
from . import views
from .logconfig import MyEmailBackend
-# logging config prior to using filter with mail_admins
-OLD_LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': False,
- 'handlers': {
- 'mail_admins': {
- 'level': 'ERROR',
- 'class': 'django.utils.log.AdminEmailHandler'
- }
- },
- 'loggers': {
- 'django.request': {
- 'handlers': ['mail_admins'],
- 'level': 'ERROR',
- 'propagate': True,
- },
- }
-}
-
class LoggingFiltersTest(SimpleTestCase):
def test_require_debug_false_filter(self):
@@ -483,13 +464,16 @@ class SetupConfigureLogging(SimpleTestCase):
"""
Calling django.setup() initializes the logging configuration.
"""
- @override_settings(
- LOGGING_CONFIG='logging_tests.tests.dictConfig',
- LOGGING=OLD_LOGGING,
- )
def test_configure_initializes_logging(self):
from django import setup
- setup()
+ try:
+ with override_settings(
+ LOGGING_CONFIG='logging_tests.tests.dictConfig',
+ ):
+ setup()
+ finally:
+ # Restore logging from settings.
+ setup()
self.assertTrue(dictConfig.called)