我对Django测试客户端有问题。
对于image_name = "J2ojU.png" # or whatever appropriate
text = pytesseract.image_to_string(Image.open(image_name), lang='eng', config='--psm 7')
路径,我有这个模板(home
):
home.html
在<html>
<body>
{% include 'example.html' %}
</body>
</html>
中我遇到了错误:
example.html
我编写了一个可访问Django URL的测试。
<div>
{% non_registered_tag arg1 arg2 %}
</div>
如果class HomePageAccess(TestCase):
def test_home_page(self):
client = Client()
response = client.get(reverse_lazy('home'))
self.assertEqual(response.status_code, 200)
中存在错误,则此代码成功失败,但是,home.html
中包含的example.html
中存在错误,即使我们希望失败,测试也会通过我将其包含在home.html
中,并且在浏览器中遇到错误(状态码500),而在测试客户端中却没有发生。
正常吗?我正在使用Django 2.0.2。 任何帮助将不胜感激
答案 0 :(得分:1)
我怀疑这里发生的事情是您在debug
设置的False
部分中将OPTIONS
选项设置为TEMPLATES
,或者您完全省略了它(在这种情况下,它将采用整体DEBUG
设置的值。
将debug
显式设置为True
应该会显示错误,并且测试应会按预期失败。
TEMPLATES = [
{
...
'OPTIONS': {
'debug': True,
},
},
]
有关debug
设置的更多信息可以在Django文档here的模板部分中找到。