获取attributeError:' testcase'对象没有属性' assertTemplateused'尝试单位测试Views.py使用Unittest框架
这是我的单位测试水果观点的代码。但是获得 attributeError
test_views.py
class TestViews(unittest.TestCase):
def test_fruit_GET(self):
client = Client()
response = client.get(reverse('products:fruit'))
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'products/fruit.html')
views.py
def fruit(request):
product = Product.objects.filter(category="Fruit")
n = Product.objects.filter(category="Fruit").count()
params = {'product': product, 'n': n}
return render(request, 'products/fruit.html', params)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此方法是Django的TestCase类的一部分,因此您需要使用它:
This method is part of django's TestCase class, so you need to use it instead:
这不适用于
unittest.testcase
。这由Django的 class [django-doc] ,所以:您可以自己实现,但是这是非常不便的:
This is not available for the
unittest.TestCase
. This is provided by Django'sTestCase
class [Django-doc], so:You can implement this yourself, but it is very inconvenient: