for Django templates

Saturday 17 January 2015

A long experiment has come to fruition: support for Django templates. I've added plugin support to, and implemented a plugin for Django templates. If you want to try it in its current alpha state, read on.

The plugin itself is pip installable:

$ pip install django_coverage_plugin

To run it, add these settings to your .coveragerc:

# Makes it slower, won't be needed eventually
timid = True

plugins =

Then run your tests under It requires >= 4.0a2, so it may not work with other coverage-related tools such as test-runner coverage plugins, or The plugin works on Django >= 1.4, and Python 2 or 3.

You will see your templates listed in your coverage report alongside your Python modules. They have a .html extension but no directory, that's still to be fixed.

The technique used to measure the coverage is the same that Dmitry Trofimov used in dtcov, but integrated into as a plugin, and made more performant. I'd love to see how well it works in a real production project. If you want to help me with it, feel free to drop me an email.

The plugin mechanism is designed to be generally useful for hooking into the collection and reporting phases of, specifically to support non-Python files. I've also got a plugin for Mako templates, but it needs some fixes from Mako. If you have non-Python files you'd like to support in, let's talk.


Add a comment:

Ignore this:
not displayed and no spam.
Leave this empty:
not searched.
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.