Skip to main content

django-test-plus provides useful additions to Django's default TestCase

Project description

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.10, 3.11, 3.12, 3.13, 3.14, and 3.15, including the free-threaded builds (3.14t and 3.15t). Python 3.15 is still in beta, so it is tested but not yet promised.

  • 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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_test_plus-2.6.2.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_test_plus-2.6.2-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file django_test_plus-2.6.2.tar.gz.

File metadata

  • Download URL: django_test_plus-2.6.2.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for django_test_plus-2.6.2.tar.gz
Algorithm Hash digest
SHA256 3b12bdc8ebd2df439f8cd5a62923acea345135f96f2bcbedfc17dec3eefb94f7
MD5 ffdde979349b65ee19298982e98a476b
BLAKE2b-256 6480d17eaf2e92fe890af9a506d6b0b51e6cb5ec73b765ded90f65b782db27d3

See more details on using hashes here.

File details

Details for the file django_test_plus-2.6.2-py3-none-any.whl.

File metadata

  • Download URL: django_test_plus-2.6.2-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for django_test_plus-2.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a7dc32e18b0941db38b6c547470e467e648605a81a11b9bc88b28ab2b04c5a8c
MD5 b878ff63c6664668e53c21bb6b96994a
BLAKE2b-256 6e7c8e9d29894c9dbe9cd435253cf28ff756630c228b9f90c491b2f101a5bda8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page