Use the class decorator syntax available in Python >= 2.6. Refs #17965.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17829 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Aymeric Augustin 2012-03-30 09:08:29 +00:00
parent 9383a2761c
commit eb163f37cb
20 changed files with 147 additions and 199 deletions

View file

@ -1450,14 +1450,13 @@ The decorator can also be applied to test case classes::
from django.test import TestCase
from django.test.utils import 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/')
LoginTestCase = override_settings(LOGIN_URL='/other/login/')(LoginTestCase)
.. note::
When given a class, the decorator modifies the class directly and
@ -1467,19 +1466,6 @@ The decorator can also be applied to test case classes::
the original ``LoginTestCase`` is still equally affected by the
decorator.
On Python 2.6 and higher you can also use the well known decorator syntax to
decorate the class::
from django.test import TestCase
from django.test.utils import 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/')
.. note::
When overriding settings, make sure to handle the cases in which your app's