django-test-plus provides useful additions to Django's default TestCase
Maintained. Last release 7 weeks ago, commits in 3 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install django-test-plusdjango-test-plus
Useful additions to Django's default TestCase from REVSYS
Rationale
Let's face it, writing tests isn't always fun. Part of the reason for that is all of the boilerplate you end up writing. django-test-plus is an attempt to cut down on some of that when writing Django tests. We guarantee it will increase the time before you get carpal tunnel by at least 3 weeks!
If you would like to get started testing your Django apps or improve how your team is testing we offer TestStart to help your team dramatically improve your productivity.
Support
-
Python 3.11, 3.12, 3.13, 3.14, and 3.15, including the free-threaded builds (3.14t and 3.15t).
-
Django 4.2 LTS, 5.1, 5.2 LTS, 6.0, and 6.1.
Installation
$ pip install django-test-plus
Usage
Have your tests inherit from test_plus.test.TestCase rather than the normal
django.test.TestCase:
from test_plus.test import TestCase
class MyViewTests(TestCase):
...
That is enough to get rolling. Here is a taste of what you get — reversing URLs, checking status codes, and inspecting context without the boilerplate:
class MyViewTests(TestCase):
def test_the_view(self):
# GET a named URL, with args or kwargs if it needs them
self.get('my-url-name')
self.response_200()
# The last response and its context are stored for you
self.assertInContext('some-key')
self.assertResponseContains('<p>Hello, World!</p>')
# POST data, then check the redirect
self.post('my-form-view', data={'name': 'Test'})
self.response_302()
def test_auth(self):
user = self.make_user('u1')
self.assertLoginRequired('my-protected-view')
with self.login(user):
self.get_check_200('my-protected-view')
def test_query_count(self):
# 200 OK in under 50 queries, in one line
self.assertGoodView('my-url-name')
