【问题标题】:Django: Getting error when unit testing the UserProfileDjango:对 UserProfile 进行单元测试时出错
【发布时间】:2012-08-09 22:12:35
【问题描述】:

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

为什么会这样?

【问题讨论】:

  • 这发生在哪一行?
  • 我已经更新了这个问题。谢谢
  • 啊这似乎是一个错误:github.com/tfausak/bauble/issues/24 解决方案显然是Fix #24; don't run Django's contrib app tests. Also skip tests for django-* packages, like compressor. 这是什么意思?我在哪里可以设置?
  • 我找到了解决办法:python manage.py test my_app my_app.ContactModelTest

标签: django unit-testing


【解决方案1】:

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

AUTH_PROFILE_MODULE = "accounts.UserProfile"

【讨论】:

  • 不,我已经设置好了。我什至把它注释掉了,我得到了一个不同的错误信息。正如我在我的 cmets 中暗示的那样,这是一个错误。应该在下一个版本中修复。我会尽快发布完整答案
猜你喜欢
  • 2013-06-14
  • 2018-11-16
  • 2013-09-29
  • 1970-01-01
  • 2017-07-21
  • 2020-03-06
  • 1970-01-01
  • 2011-01-29
  • 2016-03-12
相关资源
最近更新 更多