Question

I've recently added authentication (via django.contrib.auth of course) to my application, along with appropriate "signin"/"signup" links to my base.html.

The problem comes when I run manage.py tests, and I get 4 failures, all from django.contrib.messages.tests:

ERROR: test_middleware_disabled_anon_user (django.contrib.messages.tests.cookie.CookieTest)
ERROR: test_middleware_disabled_anon_user (django.contrib.messages.tests.fallback.FallbackTest)
ERROR: test_middleware_disabled_anon_user (django.contrib.messages.tests.user_messages.LegacyFallbackTest)
ERROR: test_middleware_disabled_anon_user (django.contrib.messages.tests.session.SessionTest)

All with the same failure:

TemplateSyntaxError: Caught NoReverseMatch while rendering: Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found.

In manage.py shell this works:

>>> from django.core.urlresolvers import reverse
>>> reverse('django.contrib.auth.views.login')
'/signin/'

However this doesn't:

>>> reverse('django.contrib.auth.views.login', (), {})
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/dave/Dropbox/Projects/statbooks.co.uk/lib/python2.6/site-packages/django/core/urlresolvers.py", line 350, in reverse
    *args, **kwargs)))
  File "/Users/dave/Dropbox/Projects/statbooks.co.uk/lib/python2.6/site-packages/django/core/urlresolvers.py", line 296, in reverse
    "arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found.

Commenting out the {% url %} tags from my base.html make the tests pass.

What's causing this?

Was it helpful?

Solution

There are several suggestions for workarounds in this Django ticket and links therein: http://code.djangoproject.com/ticket/11077 The one I like is this: http://groups.google.com/group/django-developers/msg/ec7508651e9e9fb8. To summarize, it divides up built-in tests and app tests, then overrides manage.py test to run just app tests.

None of these suggestions fixes the underlying problem (that all unit tests should be able to run even if base templates use the {% url %} tag).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top