Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Template Test Coverage

Tags:

Is there any way to produce a report containing the code coverage in my django test suite for my site's templates? I already have coverage for python, but coverage for templates to identify dead or untested template code would be awesome.

To clarify: I want to find lines in my templates that are never executed or emitted during my test suite.

like image 390
jterrace Avatar asked Mar 08 '12 06:03

jterrace


People also ask

How do I test coverage in Django?

With Django's Test Runner. If you're using manage.py test , you need to change the way you run it. You need to wrap it with three coverage commands like so: $ coverage erase # Remove any coverage data from previous runs $ coverage run manage.py test # Run the full test suite Creating test database for alias 'default'.. ...

What is Django nose?

django-nose provides all the goodness of nose in your Django tests, like: Testing just your apps by default, not all the standard ones that happen to be in INSTALLED_APPS. Running the tests in one or more specific modules (or apps, or classes, or folders, or just running a specific test)

What is Django test client?

The test client is a Python class that acts as a dummy web browser, allowing you to test your views and interact with your Django-powered application programmatically.


1 Answers

Have a look at Django Template Coverage tool: https://github.com/traff/dtcov It does exactly what you need.

EDIT: Django Template Coverage was merged to coverage.py as a plugin: http://nedbatchelder.com/blog/201501/coveragepy_for_django_templates.html

It is recommended to use it instead of original project.

like image 126
Dmitry Trofimov Avatar answered Oct 12 '22 05:10

Dmitry Trofimov