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?
--
Ticket URL: <https://code.djangoproject.com/ticket/24364>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Looks like the immediate cause is
[https://docs.djangoproject.com/en/1.7/topics/testing/overview/#other-
test-conditions 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
([http://stackoverflow.com/a/13596201/179583 as described on here]) on
every method in my Selenium test suite.
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:2>
Comment (by natevw):
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:3>
* type: Uncategorized => Cleanup/optimization
* component: Testing framework => Documentation
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:4>
* cc: cmawebsite@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:5>
* owner: nobody => aethemba
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:6>
* cc: aethemba (added)
* has_patch: 0 => 1
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:7>
* Attachment "24364.diff" added.
Diff file for ticket 24364
* Attachment "24364_revised.diff" added.
Diff for ticket #24364
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"b4d8b16e5109170614ba505e36f60c2ad64dafc2" b4d8b16]:
{{{
#!CommitTicketReference repository=""
revision="b4d8b16e5109170614ba505e36f60c2ad64dafc2"
Fixed #24364 -- Doc'ed that ManifestStaticFileStorage shouldn't be used
during testing.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"fee18ce415cd817c20f64009600b0c7158353974" fee18ce]:
{{{
#!CommitTicketReference repository=""
revision="fee18ce415cd817c20f64009600b0c7158353974"
[1.8.x] Fixed #24364 -- Doc'ed that ManifestStaticFileStorage shouldn't be
used during testing.
Backport of b4d8b16e5109170614ba505e36f60c2ad64dafc2 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"8084a68f7844ee61bcc5798c7557e2c3b4770b8a" 8084a68]:
{{{
#!CommitTicketReference repository=""
revision="8084a68f7844ee61bcc5798c7557e2c3b4770b8a"
[1.7.x] Fixed #24364 -- Doc'ed that ManifestStaticFileStorage shouldn't be
used during testing.
Backport of b4d8b16e5109170614ba505e36f60c2ad64dafc2 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24364#comment:10>