override_settings()
[source]
In case you want to override a setting for a test method, Django provides the override_settings()
decorator (see PEP 318). It’s used like this:
from django.test import TestCase, override_settings class LoginTestCase(TestCase): @override_settings(LOGIN_URL='/other/login/') def test_login(self): response = self.client.get('/sekrit/') self.assertRedirects(response, '/other/login/?next=/sekrit/')
The decorator can also be applied to TestCase
classes:
from django.test import TestCase, override_settings @override_settings(LOGIN_URL='/other/login/') class LoginTestCase(TestCase): def test_login(self): response = self.client.get('/sekrit/') self.assertRedirects(response, '/other/login/?next=/sekrit/')
Please login to continue.