【发布时间】:2013-04-22 00:48:03
【问题描述】:
我正在为一个应用编写一套测试。
在很多地方我都使用 Django 的方便的“assertTemplateUsed”。这适用于所有模板,据我所知,通过模板标签(作为包含标签对象)加载的模板除外。
当通过模板标签加载模板时,是否有另一种方法可以使用断言模板?我当然可以检查模板中的字符串,但是检查模板的使用会是一个更好的解决方案。
【问题讨论】:
标签: django django-templates django-testing
我正在为一个应用编写一套测试。
在很多地方我都使用 Django 的方便的“assertTemplateUsed”。这适用于所有模板,据我所知,通过模板标签(作为包含标签对象)加载的模板除外。
当通过模板标签加载模板时,是否有另一种方法可以使用断言模板?我当然可以检查模板中的字符串,但是检查模板的使用会是一个更好的解决方案。
【问题讨论】:
标签: django django-templates django-testing
尝试捕获template_rendered signal,它在测试期间可用。
来自文档:
django.test.signals.template_rendered
Sent when the test system renders a template. This signal is not emitted during normal operation of a Django server – it is only available during testing.
Arguments sent with this signal:
sender
The Template object which was rendered.
template
Same as sender
context
The Context with which the template was rendered.
【讨论】: