I am trying to integrate my django app with selenium to run selenium tests by manage.py test
command (I need something to automatocally run testserver).
Using django-selenium for this integration.
When I run sample project from django-selenium, it going fine. But when I run the real app which use static files, I got this:
File "env\lib\site-packages\django\core\servers\basehttp.py",
line 283, in run
self.result = application(self.environ, self.start_response)
File "env\lib\site-packages\django_selenium\selenium_server.p
y", line 45, in test_app
return handler(environ, start_response)
File "env\lib\site-packages\django\contrib\staticfiles\handle
rs.py", line 68, in __call__
return self.application(environ, start_response)
File "env\lib\site-packages\django\core\handlers\wsgi.py", li
ne 272, in __call__
response = self.get_response(request)
File "env\lib\site-packages\django\core\handlers\base.py", li
ne 153, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File env\lib\site-packages\django\core\handlers\base.py", li
ne 218, in handle_uncaught_exception
return callback(request, **param_dict)
File "env\lib\site-packages\django\utils\decorators.py", line
93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "env\lib\site-packages\django\views\defaults.py", line 3
0, in server_error
t = loader.get_template(template_name) # You need to create a 500.html templ
ate.
File "env\lib\site-packages\django\template\loader.py", line
157, in get_template
template, origin = find_template(template_name)
File "env\lib\site-packages\django\template\loader.py", line
138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
Looks like this is caused by static file handler....
How can I fix this error? DEBUG is True and I have static url handlers in urls.py
The test server always runs with DEBUG = False
; here's https://docs.djangoproject.com/en/dev/topics/testing/ :
Regardless of the value of the DEBUG setting in your configuration file, all Django tests run with DEBUG=False. This is to ensure that the observed output of your code matches what will be seen in a production setting.
So you can't rely on the DEBUG handling of static files, you need an explicit production-like way of handling them for the test to find them. You could have a special section in your urls.py
that turns on the development serve()
for when you run test
:
if 'test' in sys.argv:
static_url = re.escape(settings.STATIC_URL.lstrip('/'))
urlpatterns += patterns('',
url(r'^%s(?P<path>.*)$' % static_url, 'django.views.static.serve', {
'document_root': settings.STATIC_ROOT,
}),
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With