django_coverage_plugin: How to find templates that are never executed?

With .py files, --source will find files that were never even executed once. What’s the equivalent for template files?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 17 (5 by maintainers)

Most upvoted comments

+1 to fix this issue and +1 for every file in TEMPLATES[‘DIRS’] can be considered a template file. (people can use omit if they put non-templates in there.)

fyi, I still cannot get this plugin configured to pick up a single template.

I can’t speak for every project, but for ours, every file in TEMPLATE_DIRS is a template.

One could add optional settings for: (a) template_extensions (defaults to .*, but for most of us it will be .html) (b) If you open a file, parse it, and there’s no template language (e.g. ‘{%’ or ‘{{’), it’s not a template

But I think treating the TEMPLATE_DIRS as containing all templates will be good enough.

@charettes : I am able to see missing templates from my test run even when they are in a templates directory at the root of the project. However, the results were not exactly what I expected.

On top of changing the TEMPLATES setting, I informed .coveragerc of the new templates directory.

[run]
branch = true
omit =
    *migrations*,
    *tests*,
parallel = true
source =
    user_integration
    templates
plugins =
    django_coverage_plugin

[report]
show_missing = true
precision = 2

Output for templates dir:

Name                                                  Stmts   Miss Branch BrPart     Cover   Missing
----------------------------------------------------------------------------------------------------
templates/base.html                                      15      0      0      0   100.00%
templates/home.html                                       7      0      0      0   100.00%
templates/registration/activation_complete.html           2      0      0      0   100.00%
templates/registration/activation_email.txt               6      0      0      0   100.00%
templates/registration/activation_email_subject.txt       1      0      0      0   100.00%
templates/registration/login.html                        15      0      0      0   100.00%
templates/registration/logout.html                        2      2      0      0     0.00%   1-7
templates/registration/password_reset_done.html           2      0      0      0   100.00%
templates/registration/registration_complete.html         2      0      0      0   100.00%
templates/registration/registration_form.html             7      0      0      0   100.00%
user_integration/__init__.py                              0      0      0      0   100.00%
user_integration/apps.py                                  3      0      0      0   100.00%
user_integration/urls.py                                  6      0      0      0   100.00%
----------------------------------------------------------------------------------------------------
TOTAL                                                    68      2      0      0    97.06%

The logout.html template is definitely not being used, so it’s correctly listed as being missing.

However, running the same tests with templates in the app directory yields different results: password_reset_done.html is not covered.

Name                                                                   Stmts   Miss Branch BrPart     Cover   Missing
---------------------------------------------------------------------------------------------------------------------
user_integration/__init__.py                                               0      0      0      0   100.00%
user_integration/apps.py                                                   3      0      0      0   100.00%
user_integration/templates/base.html                                      15      0      0      0   100.00%
user_integration/templates/home.html                                       7      0      0      0   100.00%
user_integration/templates/registration/activation_complete.html           2      0      0      0   100.00%
user_integration/templates/registration/activation_email.txt               6      0      0      0   100.00%
user_integration/templates/registration/activation_email_subject.txt       1      0      0      0   100.00%
user_integration/templates/registration/login.html                        15      0      0      0   100.00%
user_integration/templates/registration/logout.html                        2      2      0      0     0.00%   1-7
user_integration/templates/registration/password_reset_done.html           2      2      0      0     0.00%   1-5
user_integration/templates/registration/registration_complete.html         2      0      0      0   100.00%
user_integration/templates/registration/registration_form.html             7      0      0      0   100.00%
user_integration/urls.py                                                   6      0      0      0   100.00%
---------------------------------------------------------------------------------------------------------------------
TOTAL                                                                     68      4      0      0    94.12%

The project is setup such that Django’s Admin template is used for password_reset_done.html instead of the local one, so my local templates should also be at 0% coverage. I suspect that when the template is in the templates directory in the root of the project, the plugin cannot differentiate between the local and admin versions (which is a bug?). Some further examination is required.

The bottom line, however, is that as long as you don’t have namespace clashes between apps, you should be able to see missing templates regardless of their location. That said, please correct me if I’m not understanding the problem.

Given that #39 was merged and implements the feature, I am closing this issue.

@schinckel : When I run tests with django_coverage_plugin, I am seeing missing template files from app directories, and have not been able to replicate conditions where they are missing. If you’re not seeing missing templates when they’re in app_name/templates please open a new issue (with code, if possible!). Thank you.

Several people expressed the desire to be able to match files that don’t end with .html or .htm. This sounds like a reasonable feature to be, so I will be opening a new issue for that.