【发布时间】:2016-06-23 09:21:16
【问题描述】:
我是 Django 测试的新手,我在我的视图中传递了一个上下文,但我的测试用例失败了。当我在 django shell 中查询 Question.objects.all() 时,我得到一个值
我的看法
def home(request):
list = Question.objects.all()
context = {'list': list}
return render(request,'index.html',context)
test.py
@pytest.mark.django_db
class TestUsers:
def test_user(self,client):
response = client.get("/test", follow=True)
assert len(response.context['list'])==1
虽然我发送上下文测试失败,但可能会发生什么改变以使我的测试用例通过
感谢任何帮助。提前致谢
【问题讨论】:
-
也许测试数据库中没有问题?你会使用固定装置吗?
-
我应该如何指定一个测试数据库..现在我只有一个数据库。
标签: python django pytest-django