运行 manage.py 测试时 django.contrib.messages.tests 中出现虚假故障
我最近向我的应用程序添加了身份验证(当然是通过 django.contrib.auth),以及指向我的 base.html 的适当的“signin”/“signup”链接。
当我运行 manage.py
测试时,问题出现了,我遇到了 4 次失败,全部来自 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)
所有失败都相同:
TemplateSyntaxError: Caught NoReverseMatch while rendering: Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found.
在 manage.py shell 这有效:
>>> from django.core.urlresolvers import reverse
>>> reverse('django.contrib.auth.views.login')
'/signin/'
但是这不起作用:
>>> 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.
注释掉我的 base.html 中的 {% url %}
标记使测试通过。
这是什么原因造成的?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此 Django 票证及其链接中提供了一些解决方法的建议: http://code.djangoproject.com/ticket /11077 我喜欢的是:http://groups. google.com/group/django-developers/msg/ec7508651e9e9fb8。总而言之,它将内置测试和应用程序测试分开,然后覆盖manage.py test以仅运行应用程序测试。
这些建议都没有解决根本问题(即使基本模板使用 {% url %} 标记,所有单元测试也应该能够运行)。
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).