[Django] #37128: Include setUpTestData as a way to speed up tests

21 views
Skip to first unread message

Django

unread,
May 29, 2026, 8:55:47 AMMay 29
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Type:
| Cleanup/optimization
Status: new | Component:
| Documentation
Version: dev | Severity: Normal
Keywords: testing | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
In Adam Johnson's book "Speed up your Django Tests", there's a section on
using `setUpTestData` to speed up tests. Since we have a section on
[https://docs.djangoproject.com/en/dev/topics/testing/overview/#speeding-
up-the-tests speeding up tests] already, I think we should add this tip to
it. We also mention in docs/topics/testing/tools.txt, that `setUpTestData`
is faster than using `setUp`.
--
Ticket URL: <https://code.djangoproject.com/ticket/37128>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 29, 2026, 9:34:35 AMMay 29
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
--------------------------------------+------------------------------------
Reporter: Tim Schilling | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: testing | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* stage: Unreviewed => Accepted

Comment:

Sounds good. I also think the `AnimalTestCase` example at the top of that
page should be updated. It's a little debatable, since part of the point
of that section is to demonstrate that `TestCase` is a lightweight
subclass of `unittest.TestCase`, and we'd be immediately showing a custom
method, but we should be able to clarify that with some appropriate
wording.
--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:1>

Django

unread,
May 29, 2026, 3:00:56 PMMay 29
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Owner: Tim
Type: | Schilling
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: testing | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Schilling):

* owner: (none) => Tim Schilling
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:2>

Django

unread,
May 29, 2026, 3:45:17 PMMay 29
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Owner: Tim
Type: | Schilling
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: testing | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Schilling):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:3>

Django

unread,
Jun 2, 2026, 12:39:07 PMJun 2
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Owner: Tim
Type: | Schilling
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: testing | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:4>

Django

unread,
Jun 2, 2026, 5:20:42 PMJun 2
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Owner: Tim
Type: | Schilling
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: testing | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Schilling):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:5>

Django

unread,
Jun 10, 2026, 2:37:46 PMJun 10
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Owner: Tim
Type: | Schilling
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: testing | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:6>

Django

unread,
Jun 15, 2026, 3:30:50 PM (13 days ago) Jun 15
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Owner: Tim
Type: | Schilling
Cleanup/optimization | Status: closed
Component: Documentation | Version: dev
Severity: Normal | Resolution: fixed
Keywords: testing | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"d80ef32eb9e669986ed7838296f6373af56c68f0" d80ef32]:
{{{#!CommitTicketReference repository=""
revision="d80ef32eb9e669986ed7838296f6373af56c68f0"
Fixed #37128 -- Doc'd setUpTestData as test speed up.

Revises the AnimalTestCase to better show test data isolation
and avoid the opportunity to use setUpTestData.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:7>

Django

unread,
Jun 15, 2026, 3:32:09 PM (13 days ago) Jun 15
to django-...@googlegroups.com
#37128: Include setUpTestData as a way to speed up tests
-------------------------------------+-------------------------------------
Reporter: Tim Schilling | Owner: Tim
Type: | Schilling
Cleanup/optimization | Status: closed
Component: Documentation | Version: dev
Severity: Normal | Resolution: fixed
Keywords: testing | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"8cfba505e113eb778dbd3b663d0e788b90194c7f" 8cfba50]:
{{{#!CommitTicketReference repository=""
revision="8cfba505e113eb778dbd3b663d0e788b90194c7f"
[6.1.x] Fixed #37128 -- Doc'd setUpTestData as test speed up.

Revises the AnimalTestCase to better show test data isolation
and avoid the opportunity to use setUpTestData.

Backport of d80ef32eb9e669986ed7838296f6373af56c68f0 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37128#comment:8>
Reply all
Reply to author
Forward
0 new messages