使用git仓库的最新master代码,使用local配置运行测试coverage run manage.py test -v2,报错如下:这种该怎么修改测试用例呢?对测试了解不多
(zanhu) [root@d29 zanhu]# coverage run manage.py test -v2
Creating test database for alias 'default' ('test_zanhu2')...
Got an error creating the test database: (1007, "Can't create database 'test_zanhu2'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_zanhu2', or 'no' to cancel: yes
Destroying old test database for alias 'default' ('test_zanhu2')...
Operations to perform:
Synchronize unmigrated apps: allauth, channels, compressor, crispy_forms, debug_toolbar, django_extensions, djcelery_email, forms, github, haystack, markdownx, messages, search, staticfiles, taskapp
Apply all migrations: account, articles, auth, contenttypes, django_comments, messager, news, notifications, qa, sessions, sites, socialaccount, taggit, thumbnail, users
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Running migrations:
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying users.0001_initial... OK
Applying account.0001_initial... OK
Applying account.0002_email_max_length... OK
Applying taggit.0001_initial... OK
Applying taggit.0002_auto_20150616_2121... OK
Applying taggit.0003_taggeditem_add_unique_index... OK
Applying articles.0001_initial... OK
Applying articles.0002_article_user... OK
Applying sites.0001_initial... OK
Applying django_comments.0001_initial... OK
Applying django_comments.0002_update_user_email_field_length... OK
Applying django_comments.0003_add_submit_date_index... OK
Applying messager.0001_initial... OK
Applying messager.0002_auto_20200331_1755... OK
Applying news.0001_initial... OK
Applying news.0002_auto_20200331_1755... OK
Applying notifications.0001_initial... OK
Applying notifications.0002_auto_20200331_1755... OK
Applying qa.0001_initial... OK
Applying qa.0002_auto_20200331_1755... OK
Applying sessions.0001_initial... OK
Applying sites.0002_alter_domain_unique... OK
Applying sites.0003_set_site_domain_and_name... OK
Applying socialaccount.0001_initial... OK
Applying socialaccount.0002_token_max_lengths... OK
Applying socialaccount.0003_extra_data_default_dict... OK
Applying thumbnail.0001_initial... OK
System check identified no issues (0 silenced).
test_object_instance (zanhu.articles.tests.test_models.ArticlesModelsTest)
判断实例对象是否为Article类型 ... ok
test_return_values (zanhu.articles.tests.test_models.ArticlesModelsTest)
测试返回值 ... ok
test_create_article (zanhu.articles.tests.test_views.ArticlesViewsTest)
测试文章创建成功后跳转 ... ok
test_draft_article (zanhu.articles.tests.test_views.ArticlesViewsTest)
测试草稿箱功能 ... FAIL
test_error_404 (zanhu.articles.tests.test_views.ArticlesViewsTest)
访问一篇不存在的文章 ... ok
test_index_articles (zanhu.articles.tests.test_views.ArticlesViewsTest)
测试文章列表页 ... ok
test_single_article (zanhu.articles.tests.test_views.ArticlesViewsTest)
测试多篇文章发表功能 ... ok
test_conversation (zanhu.messager.tests.test_models.MessagesModelsTest)
私信功能 ... ok
test_object_instance (zanhu.messager.tests.test_models.MessagesModelsTest)
测试对象是否为Message类型 ... ok
test_recent_conversation (zanhu.messager.tests.test_models.MessagesModelsTest)
最近的私信互动 ... ok
test_return_values (zanhu.messager.tests.test_models.MessagesModelsTest)
对象的返回值 ... ok
test_single_marking_as_read (zanhu.messager.tests.test_models.MessagesModelsTest) ... ok
test_send_message_view (zanhu.messager.tests.test_views.MessagesViewsTests)
发送私信 ... ok
test_user_conversation (zanhu.messager.tests.test_views.MessagesViewsTests)
私信会话 ... ok
test_user_messages (zanhu.messager.tests.test_views.MessagesViewsTests)
user01的私信 ... ok
test_wrong_requests_send_message (zanhu.messager.tests.test_views.MessagesViewsTests)
使用错误的请求方式发送私信 ... ok
test__str__ (zanhu.news.tests.test_models.NewsModelsTest) ... ok
test_reply_this (zanhu.news.tests.test_models.NewsModelsTest)
测试回复功能 ... ok
test_switch_like (zanhu.news.tests.test_models.NewsModelsTest)
测试点赞和取消赞的功能 ... ok
test_delete_news (zanhu.news.tests.test_views.NewsViewsTest)
删除动态 ... ok
test_get_thread (zanhu.news.tests.test_views.NewsViewsTest)
获取动态的评论 ... ok
test_like_news (zanhu.news.tests.test_views.NewsViewsTest)
点赞 ... ok
test_news_list (zanhu.news.tests.test_views.NewsViewsTest)
测试动态列表页功能 ... ok
test_post_comments (zanhu.news.tests.test_views.NewsViewsTest)
发表评论 ... ok
test_post_news (zanhu.news.tests.test_views.NewsViewsTest)
发送动态 ... ok
test_get_most_recent (zanhu.notifications.tests.test_models.NotificationsModelsTest) ... ok
test_mark_all_as_read (zanhu.notifications.tests.test_models.NotificationsModelsTest) ... ok
test_mark_as_read_and_return (zanhu.notifications.tests.test_models.NotificationsModelsTest) ... ok
test_notification (zanhu.notifications.tests.test_models.NotificationsModelsTest)
单个通知 ... ok
test_return_unread (zanhu.notifications.tests.test_models.NotificationsModelsTest) ... ok
test_return_values (zanhu.notifications.tests.test_models.NotificationsModelsTest)
对象类型和返回值 ... ok
test_latest_notifications (zanhu.notifications.tests.test_views.NotificationsViewsTest)
user02最近收到的通知 ... ok
test_mark_all_as_read (zanhu.notifications.tests.test_views.NotificationsViewsTest)
user01收到的所有通知标为已读 ... ok
test_mark_as_read (zanhu.notifications.tests.test_views.NotificationsViewsTest)
user01收到的某个通知标为已读,传递slug参数 ... ok
test_notification_list (zanhu.notifications.tests.test_views.NotificationsViewsTest) ... ok
test_answer_str_ (zanhu.qa.tests.test_models.QAModelsTest) ... ok
test_answered_question (zanhu.qa.tests.test_models.QAModelsTest)
已有被采纳答案的问题 ... ok
test_can_vote_answer (zanhu.qa.tests.test_models.QAModelsTest)
给回答投票 ... ok
test_can_vote_question (zanhu.qa.tests.test_models.QAModelsTest)
给问题投票 ... ok
test_get_answer_voters (zanhu.qa.tests.test_models.QAModelsTest)
回答的投票用户 ... ERROR
test_get_question_voters (zanhu.qa.tests.test_models.QAModelsTest)
问题的投票用户 ... ERROR
test_question_accepted_answer (zanhu.qa.tests.test_models.QAModelsTest)
提问者接受回答 ... ok
test_question_get_answers (zanhu.qa.tests.test_models.QAModelsTest)
获取问题的所有回答 ... ok
test_question_str_ (zanhu.qa.tests.test_models.QAModelsTest) ... ok
test_unanswered_question (zanhu.qa.tests.test_models.QAModelsTest)
未被回答的问题 ... ok
test_context_data (zanhu.qa.tests.test_views.TestAnsweredQuestionListView) ... ok
test_get (zanhu.qa.tests.test_views.TestCreateAnswerView) ... FAIL
test_get (zanhu.qa.tests.test_views.TestCreateQuestionView) ... FAIL
test_post (zanhu.qa.tests.test_views.TestCreateQuestionView) ... ok
test_accept_answer (zanhu.qa.tests.test_views.TestQAVote)
接受回答 ... ok
test_answer_downvote (zanhu.qa.tests.test_views.TestQAVote)
反对回答 ... ok
test_answer_upvote (zanhu.qa.tests.test_views.TestQAVote)
赞同问答 ... ok
test_question_downvote (zanhu.qa.tests.test_views.TestQAVote)
反对问题 ... ok
test_question_upvote (zanhu.qa.tests.test_views.TestQAVote)
赞同问题 ... ok
test_context_data (zanhu.qa.tests.test_views.TestQuestionListView) ... ok
test_context_data (zanhu.qa.tests.test_views.TestUnansweredQuestionListView) ... ok
test__str__ (zanhu.users.tests.test_models.TestUser) ... ok
test_get_absolute_url (zanhu.users.tests.test_models.TestUser) ... ok
test_get_profile_name (zanhu.users.tests.test_models.TestUser) ... ok
test_detail_resolve (zanhu.users.tests.test_urls.TestUserURLs) ... ok
test_detail_reverse (zanhu.users.tests.test_urls.TestUserURLs) ... ok
test_update_resolve (zanhu.users.tests.test_urls.TestUserURLs) ... ok
test_update_reverse (zanhu.users.tests.test_urls.TestUserURLs) ... ok
test_get_object (zanhu.users.tests.test_views.TestUserUpdateView)
get_object()函数中request请求的用户 ... ok
test_get_success_url (zanhu.users.tests.test_views.TestUserUpdateView) ... ok
======================================================================
ERROR: test_get_answer_voters (zanhu.qa.tests.test_models.QAModelsTest)
回答的投票用户
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/project/py/bb2/zanhu/zanhu/qa/tests/test_models.py", line 58, in test_get_answer_voters
assert self.user in self.answer.get_upvoters()
File "/data/project/py/bb2/zanhu/zanhu/qa/models.py", line 156, in get_upvoters
return [vote.user for vote in self.votes.filter(value=True).select_related('user').prefecth_related('vote')]
AttributeError: 'QuerySet' object has no attribute 'prefecth_related'
======================================================================
ERROR: test_get_question_voters (zanhu.qa.tests.test_models.QAModelsTest)
问题的投票用户
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/project/py/bb2/zanhu/zanhu/qa/tests/test_models.py", line 51, in test_get_question_voters
assert self.user in self.question_one.get_upvoters()
File "/data/project/py/bb2/zanhu/zanhu/qa/models.py", line 119, in get_upvoters
return [vote.user for vote in self.votes.filter(value=True).select_related('user').prefecth_related('vote')]
AttributeError: 'QuerySet' object has no attribute 'prefecth_related'
======================================================================
FAIL: test_draft_article (zanhu.articles.tests.test_views.ArticlesViewsTest)
测试草稿箱功能
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/.local/share/virtualenvs/zanhu-bgZR_2Ns/lib/python3.7/site-packages/django/test/utils.py", line 367, in inner
return func(*args, **kwargs)
File "/data/project/py/bb2/zanhu/zanhu/articles/tests/test_views.py", line 89, in test_draft_article
assert resp.context["articles"][0].slug == "cao-gao-wen-zhang"
AssertionError
======================================================================
FAIL: test_get (zanhu.qa.tests.test_views.TestCreateAnswerView)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/project/py/bb2/zanhu/zanhu/qa/tests/test_views.py", line 127, in test_get
self.assertContains(response, '编辑')
File "/root/.local/share/virtualenvs/zanhu-bgZR_2Ns/lib/python3.7/site-packages/django/test/testcases.py", line 369, in assertContains
self.assertTrue(real_count != 0, msg_prefix + "Couldn't find %s in response" % text_repr)
AssertionError: False is not true : Couldn't find '编辑' in response
======================================================================
FAIL: test_get (zanhu.qa.tests.test_views.TestCreateQuestionView)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/project/py/bb2/zanhu/zanhu/qa/tests/test_views.py", line 90, in test_get
self.assertContains(response, '标题')
File "/root/.local/share/virtualenvs/zanhu-bgZR_2Ns/lib/python3.7/site-packages/django/test/testcases.py", line 369, in assertContains
self.assertTrue(real_count != 0, msg_prefix + "Couldn't find %s in response" % text_repr)
AssertionError: False is not true : Couldn't find '标题' in response
----------------------------------------------------------------------
Ran 65 tests in 23.420s
FAILED (failures=3, errors=2)
Destroying test database for alias 'default' ('test_zanhu2')...