Visual Report for Code Coverage in Django - python

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.

Related

GitHub: publish a generated HTML report

I am wondering how it is possible to publish a generated HTML report via GitHub?
I think our use case is quite standard and it looks more or less like this:
Startup docker image
Some python setup work ( install packages from requirements.txt )
Run some python test ( slash run --with-coverage --cov . ./tests --cov-report html )
--> This generates a HTML report indicating the test coverage.
Publish that generated HTML report so that it can directly be viewed from within the browser ( without the need of downloading the report)
I am stuck with step 4. Even there is GitHub pages, it can only publish files that are actually checked in and not reports that get generated during a step in the actions.
Furthermore it seems like that via GitHub I can only specify a certain branch from where it will be published. However, I would like to have this functionality on all branches to see if coverage actually improves or not.
As mentioned, I don't think that this is a rare use case, therefore I am surprised that I don't find any resources about how to achieve this.

Finding source of manage.py subcommand

I'm new to django and working on a modern django/Wagtail CMS app that is seeded using the command python manage.py loadfixtures. It seems like loaddata is the more common command, and I'm finding it incredibly difficult to find any documentation on loadfixtures at all. Could anyone point me towards the difference? It appears under the [Core] section of "available subcommands."
As an aside, I'm essentially trying to dump and seed some static page data for the site.
loadfixtures is not a command that exists as standard on either Django or Wagtail, so it's presumably a custom command that's been added by a developer on your project, or possibly a third-party package you have installed. See Writing custom django-admin commands for documentation on how these are created - if you have a 'core' app as part of your project, you may well find the code for the command in core/management/commands/loadfixtures.py.

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

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.

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

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.

Categories

Resources