Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#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 Claude Paroz, 12 years ago

You can do that currently by deleting a setting when settings are overriden, something like:

@override_settings()
def test_something(self):
    del settings.SOME_SETTING
    ...

Sufficient or not? A documentation issue?

comment:2 by Jacob, 12 years ago

Component: Testing frameworkDocumentation
Triage Stage: UnreviewedAccepted

Agreed - documentation is the way to go.

comment:3 by Claude Paroz <claude@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 50eb70b08fae48445a52680b2d07a9535b25e3c5:

Fixed #20032 -- Documented how to simulate the absence of a setting

Thanks Ram Rachum for the report.

comment:4 by ztorstri@…, 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 Claude Paroz, 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.

comment:6 by Claude Paroz <claude@…>, 11 years ago

In 3417ba03094b644f01597d6b5a43ccbc71a55378:

Also allowed a non-overridden setting to be deleted

Refs #20032, #18824. Thanks ztorstri at gmail.com for the report.

comment:7 by Claude Paroz <claude@…>, 11 years ago

In a6eda3a5fc524333b476deed5057ee9803d91108:

[1.7.x] Also allowed a non-overridden setting to be deleted

Refs #20032, #18824. Thanks ztorstri at gmail.com for the report.
Backport of 3417ba0309 from master.

Note: See TracTickets for help on using tickets.
Back to Top