#24364 closed Cleanup/optimization (fixed)
Document that ManifestStaticFilesStorage shouldn't be used during testing
Reported by: | Nathan Vander Wilt | Owned by: | Aksel |
---|---|---|---|
Component: | Documentation | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | cmawebsite@…, Aksel | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
I recently switched a project to the ManifestStaticFilesStorage backend for the "permacacheable" URLs it gives to resources that may change. However, this seems to have broken some of my Selenium tests, which use StaticLiveServerTestCase
for the browser resources.
Now when I try to run my tests, they fail. I get a bunch of stacktraces that read
ValueError: The file 'images/favicon.ico' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x1037ed290>.
Running ./manage.py collectstatic
before the tests makes the problem go away, but this is a poor workaround (it leaves stale resources which become confusing during development). Accessing the site works just fine via ./manage.py runserver
, but is it expected for tests not to work in this configuration?
Attachments (2)
Change History (12)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Summary: | Cannot run `StaticLiveServerTestCase` when `ManifestStaticFilesStorage` used? → Tests fail when `ManifestStaticFilesStorage` used |
---|
comment:3 by , 10 years ago
This was actually breaking all my tests, irregardless of being based on StaticLiveServerTestCase
or not. A more robust workaround is to revert the STATICFILES_STORAGE
setting during tests. I now put this atop my tests.py file to work around the situation:
# WORKAROUND: https://code.djangoproject.com/ticket/24364 by reverting to default storage from django.conf import settings, global_settings settings.STATICFILES_STORAGE = global_settings.STATICFILES_STORAGE
comment:4 by , 10 years ago
Component: | Testing framework → Documentation |
---|---|
Easy pickings: | set |
Summary: | Tests fail when `ManifestStaticFilesStorage` used → Document that ManifestStaticFilesStorage shouldn't be used during testing |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
I asked Jannis about this (author of ManifestStaticFilesStorage
) and he said that you shouldn't use ManifestStaticFilesStorage
during tests, so I'll triage this as a documentation issue.
comment:5 by , 10 years ago
Cc: | added |
---|
comment:6 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 10 years ago
Cc: | added |
---|---|
Has patch: | set |
This is my first commit to Django so please bear with me.
I wrote a simple piece of documentation for this issue. I'm attaching the diff file to this ticket.
Furthermore, I've sent a pull request to Django's stable/1.7.x branch.
I'm eager to hear if I've done all steps correctly.
Looks like the immediate cause is this:
The
HashedFilesMixin
relies on debug mode to leave URLs alone, so when that is disabled it expects the manifest file generated by thecollectstatic
management command.At this point, the cleanest workaround idea I've found will be to use the
override_settings
decorator to set it back (as described on here) on every method in my Selenium test suite.