Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set stacklevel for the override_settings warning.

Refs #19031.
  • Loading branch information...
commit eabc3b6c8dd67e9ff49da9f2f41cc653898cd0a1 1 parent 1b9cbef
Aymeric Augustin aaugustin authored
Showing with 9 additions and 6 deletions.
  1. +4 −1 django/test/signals.py
  2. +5 −5 tests/settings_tests/tests.py
5 django/test/signals.py
View
@@ -97,4 +97,7 @@ def file_storage_changed(**kwargs):
@receiver(setting_changed)
def complex_setting_changed(**kwargs):
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)
10 tests/settings_tests/tests.py
View
@@ -227,13 +227,13 @@ def test_complex_override_warning(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
- override = override_settings(TEST_WARN='override')
- override.enable()
- self.assertEqual('override', settings.TEST_WARN)
- override.disable()
+ with override_settings(TEST_WARN='override'):
+ self.assertEqual(settings.TEST_WARN, 'override')
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):
Please sign in to comment.
Something went wrong with that request. Please try again.