#36680 closed Bug (fixed)
Formatters run on `TemplateCommand` make `admin_scripts` tests brittle
| Reported by: | Natalia Bidart | Owned by: | Jacob Walls |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (15)
comment:1 by , 3 weeks ago
| Has patch: | set |
|---|
comment:2 by , 3 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 3 weeks ago
| Owner: | changed from to |
|---|
comment:4 by , 3 weeks ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:5 by , 3 weeks ago
| Triage Stage: | Ready for checkin → Accepted |
|---|
comment:6 by , 3 weeks ago
| Patch needs improvement: | set |
|---|
comment:7 by , 3 weeks ago
| Patch needs improvement: | unset |
|---|
I expect some more discussion about the merit of the approach, but I pushed some edits that should handle those failures.
comment:8 by , 2 weeks ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:13 by , 10 days ago
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
There are other tests failures that need to be logged at.