diff options
| author | SnippyCodes <aaryanparik124@gmail.com> | 2026-02-28 11:06:04 +0530 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-03-19 12:36:34 -0400 |
| commit | 2d7f899deb2e3e58438a0703d6c3be4227641239 (patch) | |
| tree | 05f40eb4e7ecf97254ebe9af5e76cf4c930087fa /tests/logging_tests/tests.py | |
| parent | 1786cd881ff4ad9458d56180ae555d92c14e5af8 (diff) | |
Fixed #36958 -- Reloaded logging config when logging settings are changed in tests.
Thanks JaeHyuck Sa and Jake Howard for the reviews.
Diffstat (limited to 'tests/logging_tests/tests.py')
| -rw-r--r-- | tests/logging_tests/tests.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index a4de7424f8..9690147e81 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -573,6 +573,10 @@ class SetupConfigureLogging(SimpleTestCase): Calling django.setup() initializes the logging configuration. """ + def tearDown(self): + super().tearDown() + dictConfig.called = False + def test_configure_initializes_logging(self): from django import setup @@ -586,6 +590,44 @@ class SetupConfigureLogging(SimpleTestCase): setup() self.assertTrue(dictConfig.called) + def test_logging_settings_changed(self): + """ + Logging is reconfigured when LOGGING or LOGGING_CONFIG changes. + """ + new_logging_info = { + "version": 1, + "disable_existing_loggers": False, + "loggers": { + "django.test_custom_logger": { + "level": "INFO", + } + }, + } + new_logging_warning = { + "version": 1, + "disable_existing_loggers": False, + "loggers": { + "django.test_custom_logger": { + "level": "WARNING", + } + }, + } + logger = logging.getLogger("django.test_custom_logger") + + with override_settings(LOGGING=new_logging_info): + self.assertEqual(logger.level, logging.INFO) + + # Repeating the operation works. + with override_settings(LOGGING=new_logging_warning): + self.assertEqual(logger.level, logging.WARNING) + + # The default unconfigured level is NOTSET. + self.assertEqual(logger.level, logging.NOTSET) + + self.assertIs(dictConfig.called, False) + with override_settings(LOGGING_CONFIG="logging_tests.tests.dictConfig"): + self.assertIs(dictConfig.called, True) + @override_settings(DEBUG=True, ROOT_URLCONF="logging_tests.urls") class SecurityLoggerTest(LoggingAssertionMixin, SimpleTestCase): |
