[Django]-Django Template Test Coverage

12👍

Have a look at Django Template Coverage tool: https://github.com/traff/dtcov
It does exactly what you need.

EDIT: Django Template Coverage was merged to coverage.py as a plugin:
http://nedbatchelder.com/blog/201501/coveragepy_for_django_templates.html

It is recommended to use it instead of original project.

1👍

Templates do not store any kind of line number information like python source code does. The best you could do is monkey patch the NodeList object to record how many times each node has been evaluated, and then re-render the templates in a special mode that will show which nodes are evaluated.

EDIT: I have been corrected.

Templates DO store line number information, but only for the start of a token. I.E. if you have a TextNode span multiple lines, you will need to handle that yourself. There is some interesting code in django.templates.debug that may be useful for constructing such a coverage reporter.

👤Thomas

0👍

I don’t think you can get coverage info from templates, but you can find out which templates are rendered by connecting the template_rendered signal. Your receiver would store the names of the rendered templates.

Then, you could easily find out which templates are not rendered with the find command.

👤jpic

Leave a comment