當我嘗試在我的Django(1.4)項目運行python manage.py test
,我得到的錯誤:測試僅在Django
ERROR: test_site_profile_not_available (django.contrib.auth.tests.models.ProfileTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/contrib/auth/tests/models.py", line 29, in test_site_profile_not_available
del settings.AUTH_PROFILE_MODULE
File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 215, in __delattr__
delattr(self._wrapped, name)
AttributeError: AUTH_PROFILE_MODULE
這是一個Django的bug documented,具有recomendation只測試特定的應用程序而不是全部。但是我的項目沒有應用程序,models.py
只是駐留在項目根目錄中。要在Django測試特定應用,它看起來像this:
$ ./manage.py test animals
Note that we used animals, not myproject.animals.
這意味着它是不可能指定的根目錄來進行測試。我將如何測試我的項目目錄?
請注意,該錯誤是larger discussion on unit testing discovery的一部分。
從Django 1.6開始,有一個[new test discover runner](https://docs.djangoproject.com/en/dev/releases/1.6/#discovery-of-tests-in-any-test-module),它確切地說,django-discover-runner在1.5和更低版本中的表現。 – alfetopito