﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22071	Documentation for override_settings needs to explain how code can access overridden settings	Daniele Procida	henkvos	"https://docs.djangoproject.com/en/dev/topics/testing/tools/#overriding-settings

If you are writing tests for your own code, '''and''' you need to apply `override_settings`, '''and''' your own code makes use of settings, you need to be careful how you import the settings.

This won't work:

{{{
from django.conf import settings

SOME_SETTING = settings.SOME_SETTING

def some_func():
    ... code that does something with SOME_SETTING
}}}

because `SOME_SETTING` will be set just once, at load time, and `override_settings` won't touch it.

Instead, you will need to refer to `settings.SOME_SETTING` in your code in order to get hold of the overridden setting:

{{{
from django.conf import settings

def some_func():
    ... code that does something with settings.SOME_SETTING
}}}

This should be made clear in the documentation for `override_settings`.

(There's a wider issue, in that it's a very common pattern to have a module in an application that gets settings from `settings.py` if they're available, and provides sensible defaults if they're not, so the rest of the application can be guaranteed of finding usable settings there: 

{{{
django.conf import settings

SOME_SETTING = getattr(settings, ""SOME_SETTING"", ""some default value"")
}}}

Settings accessed in this way can't be overridden with `override_settings`, which means that an useful Django feature and a well-used Django pattern are incompatible with each other.)"	Cleanup/optimization	closed	Documentation	dev	Normal	fixed	afraid-to-commit		Accepted	0	0	0	0	1	0
