【发布时间】:2016-02-15 13:54:38
【问题描述】:
我在 views.py 中获得了 django 注销功能:
def logout_view(request):
logout(request)
return HttpResponseRedirect(reverse('cost_control_app:login'))
我正在尝试使用此代码的覆盖率对其进行测试:
class TestLogout(TestCase):
def test_logout(self):
self.client = Client()
response = self.client.get('/logout/')
但它不起作用,我的回溯没有返回:
> /home/juanda/cost_control_repository/cost_control/cost_control_app/unitary_test/test_views_authentication.py(73)TestLogout()
-> def test_logout(self):
(Pdb) n
--Return--
> /home/juanda/cost_control_repository/cost_control/cost_control_app/unitary_test/test_views_authentication.py(73)TestLogout()->None
-> def test_logout(self):
这是注销的网址:
url(r'^logout/$', views_authentication.logout_view, name = "logout"),
我认为函数根本没有被调用,但我不知道还能做什么......请帮忙??
提前致谢
【问题讨论】:
-
你能在没有 pdb 和完整的 TestLogout 类的情况下显示回溯吗?有
setUp方法创建的用户吗? -
您好,感谢您的回答。没有 pdb 的 Mmm 不显示任何错误,覆盖继续并完成,但将 logout_view 标记为未测试......这是 TestLogout 完成,那里没有更多代码,是的,我在夹具数据中创建了一个用户,但我不知道会发生什么开。
-
你能显示关于注销的 urls.py 以及它是如何匹配到 logout_view 的吗?
-
当然,看:url(r'^logout/$', views_authentication.logout_view, name = "logout"),在我的问题中也更新了。
-
如果 response 不是 None,你能打印 response.status,还是在 logout_view 中使用 pdb 断点?如果不是,我们需要确保此测试将退出 logout_view,因此问题将出现在
/logout/
标签: python django coverage.py test-coverage