Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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)

24364.diff (828 bytes ) - added by Aksel 9 years ago.
Diff file for ticket 24364
24364_revised.diff (1.3 KB ) - added by Aksel 9 years ago.
Diff for ticket #24364

Download all attachments as: .zip

Change History (12)

comment:1 by Nathan Vander Wilt, 9 years ago

Looks like the immediate cause is this:

Regardless of the value of the DEBUG setting in your configuration file, all Django tests run with DEBUG=False.

The HashedFilesMixin relies on debug mode to leave URLs alone, so when that is disabled it expects the manifest file generated by the collectstatic 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.

comment:2 by Nathan Vander Wilt, 9 years ago

Summary: Cannot run `StaticLiveServerTestCase` when `ManifestStaticFilesStorage` used?Tests fail when `ManifestStaticFilesStorage` used

comment:3 by Nathan Vander Wilt, 9 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 Tim Graham, 9 years ago

Component: Testing frameworkDocumentation
Easy pickings: set
Summary: Tests fail when `ManifestStaticFilesStorage` usedDocument that ManifestStaticFilesStorage shouldn't be used during testing
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/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 Collin Anderson, 9 years ago

Cc: cmawebsite@… added

comment:6 by Aksel, 9 years ago

Owner: changed from nobody to Aksel
Status: newassigned

comment:7 by Aksel, 9 years ago

Cc: Aksel 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.

by Aksel, 9 years ago

Attachment: 24364.diff added

Diff file for ticket 24364

by Aksel, 9 years ago

Attachment: 24364_revised.diff added

Diff for ticket #24364

comment:8 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In b4d8b16:

Fixed #24364 -- Doc'ed that ManifestStaticFileStorage shouldn't be used during testing.

comment:9 by Tim Graham <timograham@…>, 9 years ago

In fee18ce:

[1.8.x] Fixed #24364 -- Doc'ed that ManifestStaticFileStorage shouldn't be used during testing.

Backport of b4d8b16e5109170614ba505e36f60c2ad64dafc2 from master

comment:10 by Tim Graham <timograham@…>, 9 years ago

In 8084a68:

[1.7.x] Fixed #24364 -- Doc'ed that ManifestStaticFileStorage shouldn't be used during testing.

Backport of b4d8b16e5109170614ba505e36f60c2ad64dafc2 from master

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