From c1926dc77ee28a7aaa7d7521f1e2c73b5fe3a32f Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sun, 11 Sep 2011 22:34:24 -0700 Subject: [PATCH] Clean up docstring for override_settings --- analytical/tests/utils.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/analytical/tests/utils.py b/analytical/tests/utils.py index b2cd9f0..0a0731e 100644 --- a/analytical/tests/utils.py +++ b/analytical/tests/utils.py @@ -20,10 +20,26 @@ class override_settings(object): """ Temporarily override Django settings. - Acts as either a decorator, or a context manager. If it's a decorator it - takes a function and returns a wrapped function. If it's a contextmanager - it's used with the ``with`` statement. In either event entering/exiting - are called before and after, respectively, the function/block is executed. + Can be used as either a decorator on test classes/functions or as + a context manager inside test functions. + + In either case it temporarily overrides django.conf.settings so + that you can test how code acts when certain settings are set to + certain values or deleted altogether with SETTING_DELETED. + + >>> @override_settings(FOOBAR=42) + >>> class TestBaz(TestCase): + >>> # settings.FOOBAR == 42 for all tests + >>> + >>> @override_settings(FOOBAR=43) + >>> def test_widget(self): + >>> # settings.FOOBAR == 43 for just this test + >>> + >>> with override_settings(FOOBAR=44): + >>> # settings.FOOBAR == 44 just inside this block + >>> pass + >>> + >>> # settings.FOOBAR == 43 inside the test """ def __init__(self, **kwargs): self.options = kwargs