Skip to main content

django-test-plus

Useful additions to Django's default TestCase from REVSYS

pypi build matrix demo Python versions Django versions

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')

You are encouraged to create your own sub-class for your project so you can add project-specific helper methods:

# myproject/test.py
from test_plus.test import TestCase as PlusTestCase

class TestCase(PlusTestCase):
    pass

There is a pytest fixture too — ask for tp and you get the same helpers:

def test_url_reverse(tp):
    assert tp.reverse('api') == '/api/'

Documentation

Full documentation, including the complete method reference, is available at django-test-plus.readthedocs.org.

Development

To work on django-test-plus itself, clone this repository and run the following command:

$ pip install -e .
$ pip install -e .[test]

To run all tests:

$ nox

NOTE: You will also need to ensure that the test_project directory, located at the root of this repo, is in your virtualenv's path.

Keep in touch!

If you have a question about this project, please open a GitHub issue. If you love us and want to keep track of our goings-on, here's where you can find us online:

Metadata

Release files for django-test-plus 2.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-test-plus 2.7.0
File Size Uploaded
django_test_plus-2.7.0.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-test-plus 2.7.0
File Interpreter ABI Platform
django_test_plus-2.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.7 kB

Release files / django_test_plus-2.7.0.tar.gz

Download URL django_test_plus-2.7.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
83081e56479727620b937b56af9e30d3d8bf5510b26a2ce2d6b23a7018b675d8
BLAKE2b-256 checksum
How to use checksums
9dcd1a806a1f229c7dc53b50fe22bbebb488dbe045f57f27ba171979d352c5ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / django_test_plus-2.7.0-py3-none-any.whl

Download URL django_test_plus-2.7.0-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4fc9c4f66aa6e6e58312cda686b7e89f4457f5fcbb24a3037552cabf74f208c
BLAKE2b-256 checksum
How to use checksums
50765f27a2e40dd8384990de016b6a9b0993aac6e8970bc3b4f5eb4cf3808f4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

2.7.0 This release

2 release files

2.6.2

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.0

1 release file

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.4.0

1 release file

1.3.1

2 release files

1.3.0

2 release files

1.2.1

1 release file

1.2.0

2 release files

1.1.1

1 release file

1.1.0

1 release file

1.0.22

1 release file

1.0.21

1 release file

1.0.20

1 release file

1.0.19

1 release file

1.0.18

1 release file

1.0.17

1 release file

1.0.16

1 release file

1.0.15

1 release file

1.0.14

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page