1
0
mirror of https://github.com/django/django.git synced 2025-03-31 11:37:06 +00:00

[5.0.x] Fixed #34958 -- Fixed isolation of messages_tests.tests.TestLevelTags.test_lazy.

Backport of 1b56b24f81a2e64b4bd3059abad9b6fd0c801c66 from main
This commit is contained in:
nessita 2023-11-13 05:35:57 -03:00 committed by Mariusz Felisiak
parent 8eba6efbf0
commit 7a21ea5464

View File

@ -1,3 +1,5 @@
import importlib
import sys
from unittest import mock
from django.conf import settings
@ -65,8 +67,13 @@ class TestLevelTags(SimpleTestCase):
self.assertEqual(base.LEVEL_TAGS, self.message_tags)
def test_lazy(self):
storage_base_import_path = "django.contrib.messages.storage.base"
in_use_base = sys.modules.pop(storage_base_import_path)
self.addCleanup(sys.modules.__setitem__, storage_base_import_path, in_use_base)
# Don't use @override_settings to avoid calling the setting_changed
# signal.
# signal, but ensure that base.LEVEL_TAGS hasn't been read yet (this
# means that we need to ensure the `base` module is freshly imported).
base = importlib.import_module(storage_base_import_path)
old_message_tags = getattr(settings, "MESSAGE_TAGS", None)
settings.MESSAGE_TAGS = {constants.ERROR: "bad"}
try: