0

我正在使用 django-nonrel。当我运行manage.py test仅包含一个非常简单的用户定义测试的项目时,我在输出中收到以下错误。有没有人见过这个?我需要做些什么来解决问题才能test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests)成功?

/src/google_appengine/google/appengine/datastore/datastore_stub_util.py:21: DeprecationWarning: the md5 module is deprecated; use hashlib instead
    import md5
/src/google_appengine/google/appengine/api/memcache/__init__.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
    import sha
/src/google_appengine/google/appengine/api/datastore_types.py:727: DeprecationWarning: object.__init__() takes no parameters
    super(Email, self).__init__(self, email)
............................................s.................F.....................................................................................................
======================================================================
FAIL: test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/src/django/contrib/contenttypes/tests.py", line 66, in test_shortcut_view
self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
AssertionError: 'http://example.com/users/john/' != '/users/john/'

----------------------------------------------------------------------
Ran 164 tests in 9.185s

FAILED (failures=1, skipped=1)
4

2 回答 2

1

那么答案就在你的追溯中:

self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
AssertionError: 'http://example.com/users/john/' != '/users/john/'

改变拳头线:

self.assertEqual("/users/john/", response._headers.get("location")[1])

那应该修复测试。但是,如果它的测试代码不是您编写的,那么我认为问题出在 example.com/ 部分。example.com 可能来自您的站点设置。如果您将其更改为正确的 url,则有一个称为站点的模型,这可能会起作用。

您可以尝试使用不同的 django 版本。主干与稳定版本在测试期间表现不同。

于 2010-11-05T15:43:54.327 回答
0

失败是由默认 django 设置附带的单元测试引起的。

他们希望您使用管理界面配置默认站点:

例如http://localhost:8000/admin/sites/ 并拥有 SITE_ID = 1

检查站点 ID 是否引用了有效条目

http://localhost:8000/admin/sites/site/1/其中 1 是您的站点 ID。

--

使用站点应用程序是可选的,您可以从您的应用程序列表中删除:“django.contrib.sites”。

于 2011-02-21T09:31:52.000 回答