Created
April 3, 2012 19:32
-
-
Save blaix/2294982 to your computer and use it in GitHub Desktop.
Stubbing django settings with Mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SOME_SETTING = 'some value' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test import TestCase | |
from myapp.utils import get_some_setting | |
from mock import patch | |
class SimpleTest(TestCase): | |
# see http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch | |
@patch('myapp.utils.settings', SOME_SETTING='FAKED!') | |
def test_get_some_setting_returns_some_setting(self, settings): | |
assert get_some_setting() == 'FAKED!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
def get_some_setting(): | |
return settings.SOME_SETTING |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Django 1.4 provides a decoraor
@override_settings
allows you mock Django settings.So the recommended way is: