-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to find templates that are never executed? #4
Comments
I ran into this on one of my projects. I had unit tests on views, but they weren't actually calling views that rendered templates, so I wasn't getting any template coverage. Perhaps the plugin should inspect settings.TEMPLATE_DIRS and report on all files found therein? That will cover cases where the user has templates in unusual places. It might also be possible to leverage settings.TEMPLATE_LOADERS to find all templates in the project. By default, Django checks every app for a templates directory. |
One thing I'm not sure of, is how to know what are template files. With Python files, I can look for .py files. But template files could have any extension. Is it true that every file in the TEMPLATE_DIRS tree is a template? Do we need a configuration option for the plugin which is the extensions to consider as templates? |
I can't speak for every project, but for ours, every file in TEMPLATE_DIRS is a template. One could add optional settings for: But I think treating the TEMPLATE_DIRS as containing all templates will be good enough. |
You could inspire yourself on how I wrote a library that also loops through all template files in the same way, you could maybe use that as inspiration: https://github.com/sergei-maertens/django-systemjs/blob/develop/systemjs/management/commands/systemjs_bundle.py#L64 Other than that, some |
+1 to fix this issue fyi, I still cannot get this plugin configured to pick up a single template. |
For all my projects, this is true. I can't think of a reason why you would put a file in there that isn't a template. |
Just chiming in that for us every file in |
I think the mechanism that is there only looks in |
Oh wait, that's not in the released code - the HEAD in git will find all HTML files in the tested directories. My comment about |
One way this could be solved is to file a Django feature request to add a method to engines that returns all of their templates. |
Hmm. I think that might work, because I think that |
@charettes Will this return all templates that are in the tree, or only those that are actually loaded? I feel like it's the latter... |
@schinckel the idea would be for engines to return all valid identifiers they allow. The thing is not all template custom engines are file based; some third-party ones are backed by models for example. |
Given that #39 was merged and implements the feature, I am closing this issue. @schinckel : When I run tests with Several people expressed the desire to be able to match files that don't end with |
@jambonrose does it work for e.g. TEMPLATES = [
{
...
'DIRS': [os.path.join(BASE_PATH, 'templates'),
}
] |
I thought so, but you have me second-guessing myself. Let me double-check. |
@charettes : I am able to see missing templates from my test run even when they are in a On top of changing the
Output for
The However, running the same tests with templates in the app directory yields different results:
The project is setup such that Django's Admin template is used for 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. |
With .py files,
--source
will find files that were never even executed once. What's the equivalent for template files?The text was updated successfully, but these errors were encountered: