What's being used to check code coverage in Django? - python

Django doesn't appear to have built in support for code coverage. Is therea defacto-standard tool for checking it in Django 1.3?

Ned Batchelder's coverage.py is the authoritative tool for test coverage in python.

Related

Code coverage for jinja2 templates in Django

Following Ned Batchelder's Coverage.py for Django templates blog post and the django_coverage_plugin plugin for measuring code coverage of Django templates.
I would really like to see template coverage reports, but the problem is - we have replaced the Django's the template engine with jinja2 through the coffin adapter. I know it is not recommended, but we had reasons. Basically, instead of Django's render_to_response() we are using:
from coffin.shortcuts import render_to_response
Currently, we are using django-coverage's test_coverage command to run tests with coverage:
python manage.py test_coverage project_name
I understand that the setup is not common. But, is it possible to gather code coverage metrics for jinja2 templates with coverage.py? If not, I would appreciate any ideas on making a plugin similar to django_coverage_plugin, but for jinja2.
The plugin support in coverage.py is still in an alpha state. I've implemented the Django template support and half of the Mako support. A Jinja plugin would be appreciated. It might need changes in Jinja to make it feasible, in particular, to map the compiled Python code execution back to template line numbers.
If you want to start work on it, read the interfaces in plugin.py in the coverage.py source (I'll eventually write real docs, of course). The source for the Mako plugin might help also: https://bitbucket.org/ned/coverage-mako-plugin
This will likely involve us working together to get past the rough parts. Drop me an email! :)
Thanks for taking it on!
Updated: I've written some docs for the plugins, though more are needed: http://coverage.readthedocs.org/en/coverage-4.0a4/plugins.html

Visual Report for Code Coverage in Django

In rails I would use a gem called simplecov which would generate a nice html page after tests ran which would highlight where your tests are hitting(and give the percentage covered). Is there anything that can do this in Django?
Picture for reference as to what I want(This is simplecov):
coverage.py has an a command, coverage html, which generates html pages very similar to your screenshot. Here's an example from some of my own recent code:
There is documentation for how to integrate coverage into your Django testing tools at The Django Docs.

Code coverage for Jinja2 templates

I have a Pyramid web application which uses Jinja2 as template engine. It is tested using the Pyramid testing helpers together with py.test and the coverage plugin. But coverage works only for my Python code. Is there way to check also for coverage of Jinja templates?
As Jinja is compiled into Python code and as Armin mananged to give exact line numbers in the case of an exception, I should at least be possible in theory. Any hint would be very appreciated.
There is jinja_coverage.
However, it is incomplete and has a single developer with very little activity (not even published yet). You could also just take its code as hints for how to do it yourself.

How does django-nose differ from the default Django test-runner

I've been seeing and reading about a lot of people using nose to run their Django tests. I haven't been able to figure out the added benefits of using Nose to run my Django tests. If someone could fill me in on what nose is and how it adds more to a Django project, it would be helpful.
I haven't been able to find a good document/article outlining these points.
Thank you
I was curious about this too and it seems that the main advantage of django-nose using the python nose library is "Test Discovery".
In addition, from http://readthedocs.org/docs/nose/en/latest/testing.html
you can also write simple test functions, as well as test classes that are not
subclasses of unittest.TestCase. nose also supplies a number of
helpful functions for writing timed tests, testing for exceptions, and
other common use cases. See Writing tests and Testing tools for more.
From what I understand from other python developers on freenode irc, Trial test runner on Twisted Framework have these similar features like nose.
I am still not entirely convinced about using django-nose for django development but am giving a shot and report back if I find out more!
There are a lot more features overall, but I think one major reason people use nose/djano_nose is that it allows you to very easily do code coverage.
python manage.py test myapp --with-coverage --cover-package=myapp

Generate test coverage information from pyunit unittests?

I have some pyunit unit tests for a simple command line programme I'm writing. Is it possible for me to generate test coverage numbers? I want to see what lines aren't being covered by my tests.
I regularly use Ned Batchelder's coverage.py tool for exactly this purpose.
If you run your tests with testoob you can get a coverage report with --coverage. Can install with easy_install. No changes to your tests necessary:
testoob alltests.py --coverage

Categories

Resources