django_coverage_plugin icon indicating copy to clipboard operation
django_coverage_plugin copied to clipboard

Ignore lines in templates

Open mschoettle opened this issue 5 years ago • 2 comments
trafficstars

Is it possible to exclude certain lines in templates?

For example:

{% comment "foo" %}
some commented out stuff
{% endcomment %}

This will show up in the report as missing lines.

I tried adding {# pragma: no cover #} but it did not work.

mschoettle avatar May 05 '20 21:05 mschoettle

The plugin is written to understand comment blocks and ignore them. Can you provide us with a reproducible test case?

nedbat avatar May 06 '20 23:05 nedbat

I have a template file containing the above block:

{% comment "foo" %}
some commented out stuff
{% endcomment %}

And a test function like this:

def test_foo(client):
    response = client.get(reverse('app:foo'))
    ...

The relevant part of setup.cfg is as follows:

[coverage:run]
source = projectname
omit =
    .*,
    *tests*,
    *migrations*,
branch = True
plugins =
    django_coverage_plugin

Another reason why I asked is a {% block content %} definition in a base template which spans more than one line (i.e., the endblock is in a subsequent line. It's not going to be executed so I was wondering if there is a way to ignore them.

mschoettle avatar May 07 '20 01:05 mschoettle