[Django] #36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle

21 views
Skip to first unread message

Django

unread,
Oct 22, 2025, 10:11:34 AM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia | Owner: Natalia Bidart
Bidart |
Type: Bug | Status: assigned
Component: Core | Version: dev
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Some `admin_scripts` tests, such as those for `startproject`, assert
literal file contents generated from templates. Because `TemplateCommand`
runs formatters before exiting (`run_formatters(...)`), the output can
differ depending on environment details such as temporary directory path
length or whether black is installed.

For example, when `black` reformats long lines during parallel test runs,
strings in the generated `manage.py` file are wrapped in parentheses,
causing assertion failures.

Tests should not depend on the exact output of formatters. Mocking or
disabling them during test runs would make the suite more stable.
--
Ticket URL: <https://code.djangoproject.com/ticket/36680>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 22, 2025, 10:56:42 AM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
| Bidart
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:1>

Django

unread,
Oct 22, 2025, 11:52:02 AM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
| Bidart
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Unreviewed => Accepted

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

Django

unread,
Oct 22, 2025, 12:51:18 PM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* owner: Natalia Bidart => Jacob Walls

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

Django

unread,
Oct 22, 2025, 1:02:53 PM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Accepted => Ready for checkin

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

Django

unread,
Oct 22, 2025, 1:27:50 PM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Ready for checkin => Accepted

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

Django

unread,
Oct 22, 2025, 1:29:30 PM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1

Comment:

There are other tests failures that need to be logged at.
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:6>

Django

unread,
Oct 22, 2025, 2:16:19 PM10/22/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 1 => 0

Comment:

I expect some more discussion about the merit of the approach, but I
pushed some edits that should handle those failures.
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:7>

Django

unread,
Oct 27, 2025, 5:08:37 PM10/27/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:8>

Django

unread,
Oct 28, 2025, 8:02:24 AM10/28/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

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

Comment:

In [changeset:"6436ec321073bf0622af815e0af08f54c97f9b30" 6436ec32]:
{{{#!CommitTicketReference repository=""
revision="6436ec321073bf0622af815e0af08f54c97f9b30"
Fixed #36680 -- Parametrized formatter discovery in AdminScriptTestCase.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:9>

Django

unread,
Oct 29, 2025, 4:57:36 PM10/29/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"32ef95796af07b4a953f708c8636cc567411df8c" 32ef9579]:
{{{#!CommitTicketReference repository=""
revision="32ef95796af07b4a953f708c8636cc567411df8c"
[6.0.x] Fixed #36680 -- Parametrized formatter discovery in
AdminScriptTestCase.

Backport of 6436ec321073bf0622af815e0af08f54c97f9b30 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:10>

Django

unread,
Oct 30, 2025, 7:38:30 AM10/30/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by GitHub <noreply@…>):

In [changeset:"3939cd279569fde44f557d79f20bb5b1a02440af" 3939cd27]:
{{{#!CommitTicketReference repository=""
revision="3939cd279569fde44f557d79f20bb5b1a02440af"
Refs #36680 -- Fixed admin_scripts tests crash when black is not
installed.

Regression in 6436ec321073bf0622af815e0af08f54c97f9b30.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:11>

Django

unread,
Oct 30, 2025, 7:41:23 AM10/30/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"11cfb573d27661962d90c69ddda4e620255eecb6" 11cfb57]:
{{{#!CommitTicketReference repository=""
revision="11cfb573d27661962d90c69ddda4e620255eecb6"
[6.0.x] Refs #36680 -- Fixed admin_scripts tests crash when black is not
installed.

Regression in 6436ec321073bf0622af815e0af08f54c97f9b30.
Backport of 3939cd279569fde44f557d79f20bb5b1a02440af from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:12>

Django

unread,
Nov 4, 2025, 4:01:19 AM11/4/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Hal Blackburn):

I realise this ticket is closed, but I ran into this issue again (despite
it being fixed) when I was working on the PR for ticket:36704. I found
several admin_scripts tests were failing on a clean checkout after
following the repo's instructions to run tests. The fix here didn't stop
the tests failing when black is on the PATH in more than one place. (e.g.
when it's installed globally via pipx or a system package manager). I've
got a PR to extend the current fix to handle multiple instances of black
on the PATH, but I've not discussed here ahead of time as it was a small
thing to fix while working on the other ticket:
https://github.com/django/django/pull/20054
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:13>

Django

unread,
Nov 10, 2025, 2:14:00 PM11/10/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"e78420c2b8ef62acb6b7a37b71e3aa6833d630fb" e78420c2]:
{{{#!CommitTicketReference repository=""
revision="e78420c2b8ef62acb6b7a37b71e3aa6833d630fb"
Refs #36680 -- Avoided manipulating PATH in AdminScriptTestCase.

This mostly reverts 6436ec321073bf0622af815e0af08f54c97f9b30,
which was fragile. Instead, if black is present, we use it to format the
expected and actual results, instead of hard-coding the expected
formatted value.

Co-authored-by: Natalia <124304+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:14>

Django

unread,
Nov 10, 2025, 2:14:39 PM11/10/25
to django-...@googlegroups.com
#36680: Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"a26b660cff4c5b17dd0622fabcb877cff93dd858" a26b660c]:
{{{#!CommitTicketReference repository=""
revision="a26b660cff4c5b17dd0622fabcb877cff93dd858"
Refs #36680 -- Avoided manipulating PATH in AdminScriptTestCase.

This mostly reverts 6436ec321073bf0622af815e0af08f54c97f9b30,
which was fragile. Instead, if black is present, we use it to format the
expected and actual results, instead of hard-coding the expected
formatted value.

Co-authored-by: Natalia <124304+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36680#comment:15>
Reply all
Reply to author
Forward
0 new messages