#20032 closed Cleanup/optimization (fixed)
Allow override_settings to delete settings
Reported by: | Ram Rachum | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
override_settings
is used to change settings' values. Sometimes you want to delete a setting (not just set it to an empty value), and then have it restored later. override_settings
should be able to do this, probably by using some kind of constant like DELETE_FROM_SETTINGS
as the value given to it.
Change History (7)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Component: | Testing framework → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
Agreed - documentation is the way to go.
comment:3 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 11 years ago
I've read the documentation, and tried the approach above, but it doesn't work for me.
Unit test:
from django.test.utils import override_settings
from django.conf import settings
class SimpleTests(TestCase):
@override_settings()
def test_simple_settings_removal(self):
del settings.STATIC_URL
Error thrown:
======================================================================
ERROR: test_simple_settings_removal (manager_core.tests.SimpleTests)
Traceback (most recent call last):
File "/projects/Shepherd/ShepherdEnvironment/local/lib/python2.7/site-packages/django/test/utils.py", line 249, in inner
return test_func(*args, kwargs)
File "/projects/Shepherd/zach_local_cluster/trunk/manager_core/tests.py", line 76, in test_simple_settings_removal
del settings.STATIC_URL
File "/projects/Shepherd/ShepherdEnvironment/local/lib/python2.7/site-packages/django/utils/functional.py", line 249, in delattr
delattr(self._wrapped, name)
File "/projects/Shepherd/ShepherdEnvironment/local/lib/python2.7/site-packages/django/conf/init.py", line 193, in delattr
return super(UserSettingsHolder, self).delattr(name)
AttributeError: STATIC_URL
I always get attribute errors when I try to delete settings and use override_settings at the same time.
comment:5 by , 11 years ago
You are right, this works only when the setting is actually mentionned inside the override_settings
call. I'll fix this soon.
You can do that currently by deleting a setting when settings are overriden, something like:
Sufficient or not? A documentation issue?