I recently ran into a bug in our test code due to override settings resetting the settings to default after the function returned. Obviously, we shouldn't be using the override_settings decorator on a random function, but I think there is still room for improvement. At minimum, I think it would help to provide more detail in the documentation to warn against this use case.
Here's an example demonstrating the problem, we're running Django 1.5.1 with Python 2.7:
settings.py
SETTING_A = True
foo_test.py
@override_settings(SETTING_B=False)
def foo_test_func()
print settings.SETTING_A
@override_settings(SETTING_A=False)
class FooTest(TestCase):
def test_foo(self):
foo_test_func()
foo_test_func()
The above code prints out False then True.
The only related ticket I could find is:
It seems to me that foo_test_func() should be resetting the settings to the settings it originally encountered, but that was not the effect that I saw.
Best,
Daniel