Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static files not served in StaticLiveServerTestCase? #86

Closed
JonHannah opened this issue May 3, 2016 · 8 comments
Closed

Static files not served in StaticLiveServerTestCase? #86

JonHannah opened this issue May 3, 2016 · 8 comments

Comments

@JonHannah
Copy link

I'm developing a Django application with Heroku deployment. I am trying to round out test coverage with some django.test.Client get requests within a StaticLiveServerTestCase. These run fine locally, and files are served fine on the actual site, but my test fails on CircleCI / Heroku:

... ... File "/home/ubuntu/virtualenvs/venv-3.5.0/lib/python3.5/site-packages/django/contrib/staticfiles/storage.py", line 94, in hashed_name (clean_name, self)) ValueError: The file 'search/css/bootstrap.min.css' could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7f65c2a60be0>.

Not a serious blocker, but would welcome any suggestions!

@edmorley
Copy link
Contributor

edmorley commented May 3, 2016

Does the issue still exist when using the native Django storage backend (WhiteNoise's backend is only a thin wrapper around it)?
http://whitenoise.evans.io/en/stable/django.html#troubleshooting-the-whitenoise-storage-backend

@JonHannah
Copy link
Author

Thanks for the prompt response. I tried this, but in doing so realised my problem wasn't really with Whitenoise or Heroku, but actually with getting my tests to run on CircleCI. I added the below to my circle.yml file and all is well.

test:
  pre:
    - "python manage.py collectstatic --no-input"```

@edmorley
Copy link
Contributor

edmorley commented May 3, 2016

Ah yes that would do it :-)

I almost asked whether collectstatic had been run, but I read the issue description as meaning Heroku was affected too, and collectstatic is run there automatically (courtesy of this script).

Thank you for updating the ticket!

@martyzz1
Copy link

martyzz1 commented May 12, 2016

It could be worth updating the docs... I just ran into this issue on circleci too...

@JonHannah
Copy link
Author

Which docs? It actually feels like something which belongs on CircleCI docs: "Don't forget to add collecstatic if you run Django client tests"

@lisad
Copy link

lisad commented Feb 24, 2017

I've run into this problem too now, and it seems like a non-optimal workaround. Why is it working any differently on CircleCI than on my development environment? Shouldn't tests run in an environment where whitenoise pulls the static files out of their source directories not their collected destination?

@evansd
Copy link
Owner

evansd commented Feb 27, 2017

@lisad Your tests must be running with DEBUG = False, whereas you development environment is running with DEBUG = True.

It's up to you how you want to run your tests, however most people do so with debug-mode disabled so as to better replicate the production environment.

@lisad
Copy link

lisad commented Feb 27, 2017

Fair point @evansd. I suppose putting 'collectstatic' in there before the test run serves to test that the static files will be there in production as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants