- Notifications
You must be signed in to change notification settings - Fork36
A plugin for coverage.py to measure Django template execution
License
coveragepy/django_coverage_plugin
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Acoverage.py plugin to measure test coverage of Django templates.
Supported on:
- Python: 3.10 through 3.14.
- Django: 3.2 through 5.2.
- Coverage.py: 6.x or higher.
The plugin is pip-installable:
$ python3 -m pip install django_coverage_plugin
To run it, add this setting to your.coveragerc file:
[run]plugins = django_coverage_plugin
Then run your tests undercoverage.py.
You will see your templates listed in your coverage report along withyour Python modules.
If you get adjango.core.exceptions.ImproperlyConfigured error,you need to set theDJANGO_SETTINGS_MODULE environment 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 getmeasured, make sure you haveTEMPLATES.OPTIONS.debug set to True inyour settings file:
TEMPLATES= [ { ...'OPTIONS': {'debug':True, }, },]
The Django template plugin uses some existing settings from your.coveragerc file. Thesource=,include=, andomit= optionscontrol what template files are included in the report.
The plugin can find unused template and include them in your results. Bydefault, it will look for files in your templates directory with an extensionof.html,.htm, or.txt. You can configure it to look for a different set ofextensions if you like:
[run]plugins = django_coverage_plugin[django_coverage_plugin]template_extensions = html, txt, tex, email
If you usepyproject.toml for tool configuration use:
[tool.coverage.run]plugins = [ 'django_coverage_plugin',][tool.coverage.django_coverage_plugin]template_extensions = 'html, txt, tex, email'
Coverage.py can't tell whether a{% blocktrans %} tag used thesingular or plural text, so both are marked as used if the tag is used.
The technique used to measure the coverage is the same that DmitryTrofimov 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 realproduction project. If you want to help me with it, feel free to drop mean email.
The coverage.py plugin mechanism is designed to be generally useful forhooking into the collection and reporting phases of coverage.py,specifically to support non-Python files. If you have non-Python filesyou'd like to support in coverage.py, let's talk.
To run the tests:
$ python3 -m pip install -r requirements.txt$ tox
Drop Python 3.9 and Django 2.2. Add Python 3.14.
Support changes: dropped Python 3.8, added Python 3.13. Added Django 5.2.
Dropped support for Python 3.7 and Django 1.x. Declared support for Python3.12.
Dropped support for Python 2.7, Python 3.6, and Django 1.8.
Declare our support for Python 3.11 and Django 4.1.
Add support for Django 4.0.
If a non-UTF8 file was found when looking for templates, it would fail whenreading during the reporting phase, ending execution. This failure is nowraised 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 befound and believed to be unmeasured HTML template files. This is now fixed.
Test and claim our support on Python 3.10.
Drop support for Python 3.4 and 3.5.
A setting is available:template_extensions lets you set the fileextensions that will be considered when looking for unused templates(requested inissue 60).
Fix an issue on Windows where file names were being comparedcase-sensitively, causing templates to be missed (issue 46).
Fix an issue (issue 63) where tag libraries can't be found if importedduring test collection. Thanks to Daniel Izquierdo for the fix.
Add support for:
- Coverage 5
Add support for:
- Python 3.7 & 3.8
- Django 2.2 & 3.0
Add support for Django 2.1.
Validates support for Django version 2.0b1. Improves discovery oftemplate files.
Validates support for Django version 1.11. Testing for new packagemaintainer Pamela McA'Nulty
Removes support for Django versions below 1.8. Validates support forDjango version 1.11b1
Fixes another instance ofissue 32, which was the result of aninitialization order problem.
Fixesissue 32, which was the result of an initialization orderproblem.
Django 1.10.5 is now supported.
Checking settings configuration is deferred so that settings.py isincluded in coverage reporting. Fixesissue 28.
Only thedjango.template.backends.django.DjangoTemplates templateengine is supported, and it must be configured with['OPTIONS']['debug'] = True. Fixesissue 27.
Settings are read slightly differently, so as to not interfere withprograms that don't need settings. Fixesissue 18.
Multiple template engines are allowed. Thanks, Simon Charette.
No change in code, but Django 1.9.2 is now supported.
The template debug settings are checked properly for people still usingTEMPLATE_DEBUG in newer versions of Django.
Check if template debugging is enabled in the settings, and raise avisible warning if not. This prevents mysterious failures of theplugin, and fixesissue 17.
Potential Django 1.9 support is included, but the patch to Django hasn'tbeen applied yet.
Explicitly configure settings if need be to get things to work.
First version :)
About
A plugin for coverage.py to measure Django template execution
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors13
Uh oh!
There was an error while loading.Please reload this page.