0

我在 Django 中不断收到单元测试错误,我不明白。

完整的错误信息:

Creating test database for alias 'default'...
.................................................................................E.......................................................................................................................................................................................................................................................................s........................................................................
======================================================================
ERROR: test_site_profile_not_available (django.contrib.auth.tests.models.ProfileTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/tests/models.py", line 29, in test_site_profile_not_available
    del settings.AUTH_PROFILE_MODULE
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 215, in __delattr__
    delattr(self._wrapped, name)
AttributeError: AUTH_PROFILE_MODULE

----------------------------------------------------------------------
Ran 418 tests in 26.548s

FAILED (errors=1, skipped=1)
Destroying test database for alias 'default'...

更新:

我已插入完整的错误消息,甚至将测试减少到最低限度:

class ContactModelTest(TestCase):
    def setUp(self):
        ctype = ContactType.objects.create()
        ctype.contact_type= "test1"
        ctype.save()  

def test_get_contacts_user1(self):        
        ctype = ContactType.objects.all()

为什么会这样?

4

1 回答 1

0

好像您没有AUTH_PROFILE_MODULE在设置中声明。正如Django 文档所指出的,您需要通过说出您正在使用的应用程序和 UserProfile 模型来声明它,例如

AUTH_PROFILE_MODULE = "accounts.UserProfile"
于 2012-08-11T11:48:31.957 回答