Package: django-coverage-plugin
Acoverage.pyplugin to measure test coverage of Django templates.Supported on:Python: 3.8 through 3.12.Django: 2.x, 3.x and 4.x.Coverage.py: 6.x or higher.The plugin is pip installable:$ python3 -m pip install django_coverage_pluginTo run it, add this setting to your.coveragercfile:[run]
plugins = django_coverage_pluginThen run your tests undercoverage.py.You will see your templates listed in your coverage report along with
your Python modules. Please usecoverage.pyv4.4 or greater to allow
the plugin to identify untested templates.If you get adjango.core.exceptions.ImproperlyConfigurederror,
you need to set theDJANGO_SETTINGS_MODULEenvironment variable.Template coverage only works if your Django templates have debugging enabled.
If you getdjango_coverage_plugin.plugin.DjangoTemplatePluginException:
Template debugging must be enabled in settings, or if no templates get
measured, make sure you haveTEMPLATES.OPTIONS.debugset to True in
your settings file:TEMPLATES=[{...'OPTIONS':{'debug':True,},},]ConfigurationThe Django template plugin uses some existing settings from your.coveragercfile.  Thesource=,include=, andomit=options
control what template files are included in the report.The plugin can find unused template and include them in your results.  By
default, it will look for files in your templates directory with an extension
of.html,.htm, or.txt.  You can configure it to look for a different set of
extensions if you like:[run]
plugins = django_coverage_plugin

[django_coverage_plugin]
template_extensions = html, txt, tex, emailIf you usepyproject.tomlfor tool configuration use:[tool.coverage.run]
plugins = [
    'django_coverage_plugin',
]

[tool.coverage.django_coverage_plugin]
template_extensions = 'html, txt, tex, email'CaveatsCoverage.py can’t tell whether a{% blocktrans %}tag used the
singular or plural text, so both are marked as used if the tag is used.What the? How?The technique used to measure the coverage is the same that Dmitry
Trofimov used indtcov, but integrated into coverage.py 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 coverage.py plugin mechanism is designed to be generally useful for
hooking into the collection and reporting phases of coverage.py,
specifically to support non-Python files.  If you have non-Python files
you’d like to support in coverage.py, let’s talk.TestsTo run the tests:$ python3 -m pip install -r requirements.txt
$ toxHistoryv3.1.0 — 2023-07-10Dropped support for Python 3.7 and Django 1.x.  Declared support for Python
3.12.v3.0.0 — 2022-12-06Dropped support for Python 2.7, Python 3.6, and Django 1.8.v2.0.4 — 2022-10-31Declare our support for Python 3.11 and Django 4.1.v2.0.3 — 2022-05-04Add support for Django 4.0.v2.0.2 — 2021-11-11If a non-UTF8 file was found when looking for templates, it would fail when
reading during the reporting phase, ending execution.  This failure is now
raised in a way that can be ignored with a .coveragerc setting of[report] ignore_errors=True(issue 78).When usingsource=., an existing coverage HTML report directory would be
found and believed to be unmeasured HTML template files.  This is now fixed.v2.0.1 — 2021-10-06Test and claim our support on Python 3.10.v2.0.0 — 2021-06-08Drop support for Python 3.4 and 3.5.A setting is available:template_extensionslets you set the file
extensions that will be considered when looking for unused templates
(requested inissue 60).Fix an issue on Windows where file names were being compared
case-sensitively, causing templates to be missed (issue 46).Fix an issue (issue 63) where tag libraries can’t be found if imported
during test collection. Thanks to Daniel Izquierdo for the fix.v1.8.0 — 2020-01-23Add support for:Coverage 5v1.7.0 — 2020-01-16Add support for:Python 3.7 & 3.8Django 2.2 & 3.0v1.6.0 — 2018-09-04Add support for Django 2.1.v1.5.2 — 2017-10-18Validates support for Django version 2.0b1. Improves discovery of
template files.v1.5.1a — 2017-04-05Validates support for Django version 1.11. Testing for new package
maintainer Pamela McA’Nultyv1.5.0 — 2017-02-23Removes support for Django versions below 1.8.  Validates support for
Django version 1.11b1v1.4.2 — 2017-02-06Fixes another instance ofissue 32, which was the result of an
initialization order problem.v1.4.1 — 2017-01-25Fixesissue 32, which was the result of an initialization order
problem.v1.4 — 2017-01-16Django 1.10.5 is now supported.Checking settings configuration is deferred so that settings.py is
included in coverage reporting.  Fixesissue 28.Only thedjango.template.backends.django.DjangoTemplatestemplate
engine is supported, and it must be configured with['OPTIONS']['debug']= True. Fixesissue 27.v1.3.1 — 2016-06-02Settings are read slightly differently, so as to not interfere with
programs that don’t need settings.  Fixesissue 18.v1.3 — 2016-04-03Multiple template engines are allowed.  Thanks, Simon Charette.v1.2.2 — 2016-02-01No change in code, but Django 1.9.2 is now supported.v1.2.1 — 2016-01-28The template debug settings are checked properly for people still usingTEMPLATE_DEBUGin newer versions of Django.v1.2 — 2016-01-16Check if template debugging is enabled in the settings, and raise a
visible warning if not.  This prevents mysterious failures of the
plugin, and fixesissue 17.Potential Django 1.9 support is included, but the patch to Django hasn’t
been applied yet.v1.1 — 2015-11-12Explicitly configure settings if need be to get things to work.v1.0 — 2015-09-20First version :)