diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-10-09 04:50:47 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-10-09 04:50:47 +0000 |
| commit | b7a73cf9296a2629a45d4b303c2b9207d3c71c40 (patch) | |
| tree | f2d6d74b946695c98a5f078146a4711ef2e301dc /docs | |
| parent | 816c7d1e644f72563ee4a86582bb98ea3b1922e4 (diff) | |
Fixed #14378 -- Made the test client class customizable. Thanks to Ned Batchelder for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14058 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/testing.txt | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt index 28e67b438c..28411ab05f 100644 --- a/docs/topics/testing.txt +++ b/docs/topics/testing.txt @@ -1086,6 +1086,30 @@ This means, instead of instantiating a ``Client`` in each test:: response = self.client.get('/customer/index/') self.failUnlessEqual(response.status_code, 200) +Customizing the test client +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 1.3 + +.. attribute:: TestCase.client_class + +If you want to use a different Client class (for example, a subclass +with customized behavior), you can use the +:attr:`~TestCase.client_class` class attribute to specify a custom +``Client`` class in your test case:: + + from django.test import TestCase + from django.test.client import Client + + class MyTestClient(Client): + # .. specialized methods for your environment .. + + class MyTest(TestCase): + client_class = MyTestClient + + def test_my_stuff(self): + # .. Here self.client is an instance of MyTestClient .. + .. _topics-testing-fixtures: Fixture loading |
