django-test-plus

raw JSON →
2.4.1 verified Mon Apr 27 auth: no python

Useful additions to Django's default TestCase, such as shortcut assertions and improved request factory. Current version is 2.4.1, updated 2025-03, maintained by REVSYS. Release cadence is irregular, roughly 1-2 minor versions per year.

pip install django-test-plus
error ModuleNotFoundError: No module named 'test_plus'
cause Package not installed or import path is wrong (e.g., using 'django_test_plus' or 'testplus').
fix
Install: pip install django-test-plus. Import: from test_plus import TestCase
error AttributeError: 'MyViewTest' object has no attribute 'assert_200'
cause Your test class does not inherit from test_plus.TestCase, but from django.test.TestCase.
fix
Change class declaration to: class MyViewTest(test_plus.TestCase):
error TypeError: __init__() got an unexpected keyword argument 'follow'
cause You passed 'follow=True' to get_check_200 or post_check_200 methods; they don't support that parameter.
fix
Use self.client.get(url, follow=True) directly and then check status and content manually.
breaking In v2.0, support for Django < 3.2 and Python < 3.6 was dropped. Also, the `reverse()` method no longer automatically appends trailing slashes; you must include them explicitly.
fix Upgrade to Django >= 3.2 and Python >= 3.6. Ensure your URLs include trailing slashes where expected.
deprecated The `TransactionTestCase` class from `test_plus` is deprecated in favor of using Django's built-in `TransactionTestCase` or the `test_plus.TestCase` with appropriate database settings.
fix Use `django.test.TransactionTestCase` or `test_plus.TestCase` with `transaction=True`.
gotcha The `get_check_200` method (and similar) calls `self.client.get()` which does not follow redirects. If your view redirects, you need to use `self.client.get()`, `assert_redirects()` manually.
fix For views that redirect, use `self.client.get(url, follow=True)` or check redirect status explicitly with `assert_302` or `assert_redirects`.

Subclass `test_plus.TestCase` to get additional assertions like `assert_200`, `assert_contains`, `get_check_200`, and improved request factory.

from test_plus import TestCase

class MyViewTest(TestCase):
    def test_get(self):
        response = self.client.get('/my-view/')
        self.assert_200(response)
        self.assert_contains(response, 'Hello')