Skip to main content

django-timed-tests

What gets measured gets improved.

django-timed-tests produce the timing breakdown for your tests.

Requirements

Note: as of cpython 3.12, timing functionality is supported by default

Python 3.6 through 3.12 supported.

Django 2.0 through 4.2 supported.

django-timed-tests only works if you're using Django's testing framework.

Installation

Install using pip:

python -m pip install django-timed-tests

Usage

Edit your settings.py:

INSTALLED_APPS = [
    ...
    django_timed_tests,
    ...
]

TEST_RUNNER = "django_timed_tests.TimedTestRunner"

django-timed-tests support the use of --parallel, --debug-sql, and --pdb flags.

Regular report

The regular report shows 10 slowest passing tests that were run, ordered by descending duration.

The next time you run your tests using manage.py test, you'll see something like:

.............
----------------------------------------------------------------------
Ran 12 tests in 18.036s

OK
| Test                                       |   Duration (s) |
|--------------------------------------------|----------------|
| tests.examples.DummyTestCase1.test_dummy_3 |    3.0048      |
| tests.examples.DummyTestCase3.test_dummy_3 |    3.0041      |
| tests.examples.DummyTestCase2.test_dummy_3 |    3.00086     |
| tests.examples.DummyTestCase3.test_dummy_2 |    2.0052      |
| tests.examples.DummyTestCase1.test_dummy_2 |    2.00372     |
| tests.examples.DummyTestCase2.test_dummy_2 |    2.00194     |
| tests.examples.DummyTestCase3.test_dummy_1 |    1.0043      |
| tests.examples.DummyTestCase1.test_dummy_1 |    1.00235     |
| tests.examples.DummyTestCase2.test_dummy_1 |    1.00044     |
| tests.examples.DummyTestCase3.test_dummy_0 |    0.000109295 |

Full report

Full report shows all passing tests, with a breakdown per module, test class, and test method.

When you run manage.py test --full-report, you'll see something like:

..............
----------------------------------------------------------------------
Ran 12 tests in 6.157s

OK
| Module         |   Duration (s) |
|----------------|----------------|
| tests.examples |        18.0088 |

| Class                         |   Duration (s) |
|-------------------------------|----------------|
| tests.examples.DummyTestCase1 |        6.00306 |
| tests.examples.DummyTestCase2 |        6.00299 |
| tests.examples.DummyTestCase3 |        6.00273 |

| Test                                       |   Duration (s) |
|--------------------------------------------|----------------|
| tests.examples.DummyTestCase2.test_dummy_3 |    3.00136     |
| tests.examples.DummyTestCase3.test_dummy_3 |    3.00136     |
| tests.examples.DummyTestCase1.test_dummy_3 |    3.00126     |
| tests.examples.DummyTestCase3.test_dummy_2 |    2.00039     |
| tests.examples.DummyTestCase1.test_dummy_2 |    2.00031     |
| tests.examples.DummyTestCase2.test_dummy_2 |    2.00026     |
| tests.examples.DummyTestCase1.test_dummy_1 |    1.00128     |
| tests.examples.DummyTestCase2.test_dummy_1 |    1.00112     |
| tests.examples.DummyTestCase3.test_dummy_1 |    1.0008      |
| tests.examples.DummyTestCase2.test_dummy_0 |    0.000246959 |
| tests.examples.DummyTestCase1.test_dummy_0 |    0.00022184  |
| tests.examples.DummyTestCase3.test_dummy_0 |    0.000178818 |

Combining with your own test runner

TimedTestRunner tries to be minimally invasive, and integrating it into your custom test runner shouldn't be too complex.

If your custom runner just inherits from DiscoverRunner, without redefining DiscoverRunner.test_runner, DiscoverRunner.parallel_test_runner and DiscoverRunner.get_resultclass, you should be fine with just inheriting TimedTestRunner and calling super() at the beginning of your overriden methods:

class MyOwnTestRunner(TimedTestRunner):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        # Do something else

    ...

If your test runner also uses custom TestRunner or TestResult classes, best course of action would be to inspect the django_timed_tests.runner module to see which classes should be inherited and which attributes and method should be overridden.

Release files for django-timed-tests 0.1.4

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-timed-tests 0.1.4
File Size Uploaded
django-timed-tests-0.1.4.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-timed-tests 0.1.4
File Interpreter ABI Platform
django_timed_tests-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / django-timed-tests-0.1.4.tar.gz

Download URL django-timed-tests-0.1.4.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
44820a45bebb8ecc07e09e77231c56710a6e3c5b31b8749791a3bbe5e119b33c
BLAKE2b-256 checksum
How to use checksums
a8141ef9cb2def124767a319e66b6f3addbb5ee755615b74abd97f63c1803b2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release files / django_timed_tests-0.1.4-py3-none-any.whl

Download URL django_timed_tests-0.1.4-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c01cb09b4fdf29e6c67fdc76935f3cf8aa1b4b3277c6754f018058b398f2c8ab
BLAKE2b-256 checksum
How to use checksums
f4b36c6ff3516765a5d9c5bb81beabbc0986f36251410207b9c97a45ce0f0bc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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