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:

https://code.djangoproject.com/ticket/18417

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cab408a0-8e12-4ede-84ba-e72cf32b971b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to