On Thu, Nov 4, 2010 at 3:46 PM, David Cramer <[email protected]> wrote:
> A common behavior I seem to have is the need to tweak the settings
> object for certain test cases. The other case is that in many cases we
> were (are?) relying on settings being configured a certain way for the
> Django tests to even work. I brought this up in #django-dev a while
> back, but wanted to open it up to further discussion.
>
> Let me start with an example test:
>
> def test_with_awesome_setting(self):
> _orig = getattr(settings, 'AWESOME', None)
> settings.AWESOME = True
>
> # do my test
> ...
>
> settings.AWESOME = _orig
>
> So the obvious problem for me here is that I'm repeating this same
> code flow in a lot of situations. Ignoring the fact that it's ugly,
> it's just not fun mangling with settings like this (at least, not fun
> having to reset the values).
>
> My proposal is to include some kind of utility within the test suite
> which would make this easier. There's a couple ways I could see this
> working:
>
> 1. The settings object could be copied and reset on each case.
> 2. The settings object could be replaced with a Proxy which stores a
> copy of any value changed since reset, and returns that value if
> present. It could then simply just be reset (clear the proxy's dict)
> on each setUp.
>
> Anyways, I'd love to hear how others have dealt with this and any
> other possible solutions.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-developers?hl=en.
>
>
Russ and I discussed having a decorator/context manager for monkey
patching settings:
@swap_settings(TEMPLATE_DIRS=[fuzzy], DEBUG=True)
def test_who_cares(self):
self.assertTrue(settings.DEBUG)
or
with swap_settings(DEBUG=True):
self.assertTrue(settings.DEBUG)
Alex
--
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.