Django template coverage experiment

58 views
Skip to first unread message

Ned Batchelder

unread,
Jan 15, 2015, 7:26:21 PM1/15/15
to django-d...@googlegroups.com
Hi,

I've added support to coverage.py for plugins to support non-Python files, and I've written a plugin to measure Django templates.  I'm looking for a collaborator to decide how to complete the work.  I'm asking on the dev list because ideally, the plugin would be part of Django itself, although it doesn't have to be.  There are also possibilities to change the template engine slightly to make coverage measurement of templates better.

If you'd like to try it, the plugin itself is pip installable: pip install django_coverage_plugin . To run it, add these settings to your .coveragerc:
[run]
timid = True   # won't be needed eventually
plugins =
    django_coverage_plugin
Then run your tests under coverage as you normally would.  It requires coverage.py>=4.0a2, so it may not work with other coverage-related tools if you have them, such as coveralls.io.  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 coverage.py, 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, feel free to reply offlist if it's more appropriate.

Thanks,

--Ned.
Reply all
Reply to author
Forward
0 new messages