我關閉了Django主幹,注意到主幹中Django模塊的單元測試總是失敗。 Django主幹應該通過它所有的單元測試嗎?如果Django的中繼單元測試失敗會怎麼辦?
下面是一些例子錯誤:
====================================================================== ERROR: test_password_change_fails_with_invalid_old_password (django.contrib.auth.tests.views.ChangePasswordTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/michael/django/trunk/django/contrib/auth/tests/views.py", line 156, in test_password_change_fails_with_invalid_old_password 'new_password2': 'password1', File "/Users/michael/django/trunk/django/test/client.py", line 318, in post response = self.request(**r) File "/Users/michael/django/trunk/django/core/handlers/base.py", line 87, in get_response response = middleware_method(request, callback, callback_args, callback_kwargs) File "/Users/michael/Documents/workspace/drchrono/drchrono_middleware/drchrono.py", line 31, in process_view setattr(request, 'currentDoctor', request.user.get_profile().doctor) #Default is to have currentDoctor be default for logged in user. File "/Users/michael/django/trunk/django/contrib/auth/models.py", line 285, in get_profile self._profile_cache = model._default_manager.get(user__id__exact=self.id) File "/Users/michael/django/trunk/django/db/models/manager.py", line 119, in get return self.get_query_set().get(*args, **kwargs) File "/Users/michael/django/trunk/django/db/models/query.py", line 298, in get % self.model._meta.object_name) DoesNotExist: UserProfile matching query does not exist.
我才意識到,很多錯誤的提缺少用戶配置,並且我有我創建通過新用戶時創建一個自定義用戶配置對象Web註冊過程(但是在管理員中實例化一個新的User對象時並未創建,或者我將通過代碼假設)。所以,也許這是我的應用程序的錯誤,因爲未爲通過GUI創建的用戶創建UserProfiles。我如何爲每個創建的用戶對象創建一個UserProfile?你是否用monkeypatch User類的new()方法?
我認爲這可能是由於我的開發設置。我使用的是OSX和MySQL,大多數失敗似乎是重命名錶等數據庫相關的。 – MikeN 2009-10-28 15:47:46
OSX和MySQL都完全支持,所以還是值得一問。我確信Django團隊會更喜歡你可以自信地運行測試。 – 2009-10-28 17:37:43