Kaydet (Commit) eabc3b6c authored tarafından Aymeric Augustin's avatar Aymeric Augustin

Set stacklevel for the override_settings warning.

Refs #19031.
üst 1b9cbef1
...@@ -97,4 +97,7 @@ def file_storage_changed(**kwargs): ...@@ -97,4 +97,7 @@ def file_storage_changed(**kwargs):
@receiver(setting_changed) @receiver(setting_changed)
def complex_setting_changed(**kwargs): def complex_setting_changed(**kwargs):
if kwargs['enter'] and kwargs['setting'] in COMPLEX_OVERRIDE_SETTINGS: if kwargs['enter'] and kwargs['setting'] in COMPLEX_OVERRIDE_SETTINGS:
warnings.warn("Overriding setting %s can lead to unexpected behaviour." % kwargs['setting']) # Considering the current implementation of the signals framework,
# stacklevel=5 shows the line containing the override_settings call.
warnings.warn("Overriding setting %s can lead to unexpected behaviour."
% kwargs['setting'], stacklevel=5)
...@@ -227,13 +227,13 @@ class TestComplexSettingOverride(TestCase): ...@@ -227,13 +227,13 @@ class TestComplexSettingOverride(TestCase):
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always") warnings.simplefilter("always")
override = override_settings(TEST_WARN='override') with override_settings(TEST_WARN='override'):
override.enable() self.assertEqual(settings.TEST_WARN, 'override')
self.assertEqual('override', settings.TEST_WARN)
override.disable()
self.assertEqual(len(w), 1) self.assertEqual(len(w), 1)
self.assertEqual('Overriding setting TEST_WARN can lead to unexpected behaviour.', str(w[-1].message)) self.assertEqual(w[0].filename, __file__)
self.assertEqual(str(w[0].message),
'Overriding setting TEST_WARN can lead to unexpected behaviour.')
class UniqueSettingsTests(TestCase): class UniqueSettingsTests(TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment