Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #17895 -- Made override_settings send the setting_changed signa…

…l both when a setting is overridden and when it's restored.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 2a0f457 commit 4b14546215ad4ef15f04e748e3b5f0da7b613b45 @aaugustin aaugustin committed
19 django/test/
@@ -167,15 +167,6 @@ def restore_template_loaders():
delattr(loader, RESTORE_LOADERS_ATTR)
-class OverrideSettingsHolder(UserSettingsHolder):
- """
- A custom setting holder that sends a signal upon change.
- """
- def __setattr__(self, name, value):
- UserSettingsHolder.__setattr__(self, name, value)
- setting_changed.send(sender=self.__class__, setting=name, value=value)
class override_settings(object):
Acts as either a decorator, or a context manager. If it's a decorator it
@@ -215,10 +206,18 @@ def inner(*args, **kwargs):
return inner
def enable(self):
- override = OverrideSettingsHolder(settings._wrapped)
+ override = UserSettingsHolder(settings._wrapped)
for key, new_value in self.options.items():
setattr(override, key, new_value)
settings._wrapped = override
+ for key, new_value in self.options.items():
+ setting_changed.send(sender=settings._wrapped.__class__,
+ setting=key, value=new_value)
def disable(self):
settings._wrapped = self.wrapped
+ for key in self.options:
+ new_value = getattr(settings, key, None)
+ setting_changed.send(sender=settings._wrapped.__class__,
+ setting=key, value=new_value)
10 docs/ref/signals.txt
@@ -477,20 +477,24 @@ setting_changed
.. data:: django.test.signals.setting_changed
-Sent when some :ref:`settings are overridden <overriding-settings>` with the
+This signal is sent when the value of a setting is changed through the
:meth:`django.test.TestCase.setting` context manager or the
:func:`django.test.utils.override_settings` decorator/context manager.
+It's actually sent twice: when the new value is applied ("setup") and when the
+original value is restored ("teardown").
Arguments sent with this signal:
The settings handler.
- Same as sender
+ The name of the setting.
- The new setting value.
+ The value of the setting after the change. For settings that initially
+ don't exist, in the "teardown" phase, ``value`` is ``None``.
1  tests/regressiontests/settings_tests/
@@ -132,6 +132,7 @@ def test_signal_callback_context_manager(self):
self.assertRaises(AttributeError, getattr, settings, 'TEST')
with self.settings(TEST='override'):
self.assertEqual(testvalue, 'override')
+ self.assertEqual(testvalue, None)
def test_signal_callback_decorator(self):

0 comments on commit 4b14546

Please sign in to comment.
Something went wrong with that request. Please try again.