Django:单元测试UserProfile时出错

时间:2012-08-09 22:12:35

标签: django unit-testing

我一直在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()

为什么会这样?

1 个答案:

答案 0 :(得分:0)

您的设置中似乎没有声明AUTH_PROFILE_MODULE。作为Django documentation indicates,您需要通过说出您正在使用的应用程序和UserProfile模型来声明它,例如

AUTH_PROFILE_MODULE = "accounts.UserProfile"