Opened 4 months ago

Closed 4 months ago

Last modified 3 months ago

#35662 closed Bug (invalid)

running tests now requires static files to be generated when using ManifestStaticFilesStorage

Reported by: Patrick Rauscher Owned by:
Component: contrib.staticfiles Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Patrick Rauscher)

Hello everyone,

while migrating from django 5.0.8 to 5.1, I experienced a change in behavior when running unittests. We are using ManifestStaticFilesStorage, and during development and unittesting, collectstatic have never been called, as static files were only required for the final result.

This did not pose a problem in 5.0.8, but after switching to 5.1, tests using templates with static-templatetags failed with "Missing staticfiles manifest entry for 'admin/css/base.css'".

Of course, there are multiple ways to fix this for a given project, such as

  • changing settings.py to use simple StaticFilesStorage during tests (e.g. detected by environment variable)
  • running collectstatic before running tests

But, as the problem is not described in Release Notes or https://docs.djangoproject.com/en/5.0/topics/testing/overview/, users might be puzzled first.
Not sure what the best way to deal with this issue would be, but maybe it could at least be added to documentation?

Change History (4)

comment:1 by Patrick Rauscher, 4 months ago

Description: modified (diff)

comment:2 by Natalia Bidart, 4 months ago

Component: Documentationcontrib.staticfiles
Resolution: needsinfo
Status: newclosed

Hello Patrick, thank you for your ticket!

Could you please provide a small Django project or a test case to reproduce? Ideally you could also bisect the commit that introduced this behavior.

Given the above, I'll close the ticket accordingly, but please re-open when you can provides the extra details. Thanks again!

comment:3 by Patrick Rauscher, 3 months ago

Hey Natalia,

thank you for your comment - I spend some time debugging the issue and have to admit the issue is within my test case definition: I used

@override_settings(STATICFILES_STORAGE="django.contrib.staticfiles.storage.StaticFilesStorage")
class MainTestCase(django.test.TestCase): ...

as a Main Test-Class and inherited my other TestCases from this MainTestCase, forgetting about this override in the process.
As STATICFILES_STORAGE got removed in 5.1, this override didn't work any longer and test cases broke.

As deprecation of STATICFILES_STORAGE is documented, there is no change needed, this comment should just serve as information for any poor soul reaching the ticket by google :)

Updating the override to STORAGES=... did obviously help.

comment:4 by Natalia Bidart, 3 months ago

Resolution: needsinfoinvalid

Amazing, thank you Patrick for sharing your conclusions. I'll change the ticket resolution accordingly then.

Note: See TracTickets for help on using tickets.
Back to Top