PipelineCachedStorage breaks app tests
See original GitHub issueI made a test app to highlight this bug: https://github.com/amarandon/trypipeline/tree/with-pipeline
I have a trivial test:
from django.test import TestCase
class TestHome(TestCase):
def test_home(self):
response = self.client.get('/')
self.assertContains(response, 'css')
As soon as I add this to my settings:
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
The test breaks with this error:
Traceback (most recent call last):
File "/home/al/projects/trypipeline/main/tests.py", line 7, in test_home
response = self.client.get('/')
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/test/client.py", line 473, in get
response = super(Client, self).get(path, data=data, **extra)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/test/client.py", line 280, in get
return self.request(**r)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/test/client.py", line 444, in request
six.reraise(*exc_info)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/utils/six.py", line 491, in reraise
raise value
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/core/handlers/base.py", line 114, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/al/projects/trypipeline/main/views.py", line 5, in home
return render(request, 'main/home.html')
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/shortcuts/__init__.py", line 53, in render
return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/template/loader.py", line 169, in render_to_string
return t.render(context_instance)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/template/base.py", line 140, in render
return self._render(context)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/test/utils.py", line 85, in instrumented_test_render
return self.nodelist.render(context)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/templatetags/static.py", line 106, in render
url = self.url(context)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/contrib/staticfiles/templatetags/staticfiles.py", line 12, in url
return staticfiles_storage.url(path)
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/contrib/staticfiles/storage.py", line 134, in url
hashed_name = self.hashed_name(clean_name).replace('\\', '/')
File "/home/al/projects/env/dummy/lib/python3.3/site-packages/django/contrib/staticfiles/storage.py", line 91, in hashed_name
(clean_name, self))
ValueError: The file 'main/css/style.css' could not be found with <pipeline.storage.PipelineCachedStorage object at 0x7f853a37b850>.
Executing collectstatic solves this error. This is confusing because tests usually don’t require to run collectstatic. If this hard to fix in the code, we should probably mention this issue in the documentation with possible workarounds such as executing collectstatic before running tests or running test with settings that don’t enable PipelineCachedStorage. If this is the way to go then I’ll be happy to do a doc PR.
Tried against the master branch, commit 68646764b68a43e6136254c3aa5c27e2ad50f008 Django 1.6, Python 3.3.1
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
ValueError: The file could not be found with <pipeline.storage ...
Then I tried to find the static file: F:\DEV\DJANGO\apps\test> python manage.py findstatic css/main.css No matching file found for ...
Read more >Storages — django-pipeline 2.0.0 documentation
If you use PipelineCachedStorage you may also like the CachedFileFinder , which allows you to use integration tests with cached file URLs.
Read more >Make tests a part of your app - sobolevn.me
Right now the status-quo for source code/tests dualism is that you ... Why ZeroDivisionError didn't break the test while raw Exception did?
Read more >How to run all tests in INSTALLED_APPS with the new test ...
If I try to specify another app to test by doing something like "django test a_dependency" I get an exception from Python's unittest...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I too am running into this issue. I’ve added the following to my
settings.pyto workaround this issue.Perfect! @jdufresne