coveragepy / coveragepy/django_coverage_plugin

Widget templates not covered (when they are clearly used).

Open
#94 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
202
Forks
38
PR merge metrics
No merged PRs in 30d

Description

I have Widget such as:

class PlanChoiceWidget(RadioSelect):
    option_template_name = "plans/plan_choice_widget.html"

and tests such as:

class PlanChoiceWidgetTests1(TestCase):

    def setUp(self):
        self.factory = RequestFactory()
        self.plan_pricing = baker.make(
            "PlanPricing", plan__name="Foo", price=Decimal("10.00"),
            has_automatic_renewal=True
        )
        self.request = self.factory.get("")
        self.request.user = baker.make("accounts.UserProfile")

    def render_widget(self, plan):
        widget = PlanChoiceWidget()
        choice_data = {
            "name": "plan_choice",
            "value": plan.pk,
            "attrs": {"id": "id_plan_choice"},
        }
        widget.choices = [(plan.pk, plan)]
        widget.request = self.request
        return widget.render(**choice_data)

    def test_plan_choice_widget_render(self):
        rendered_html = self.render_widget(self.plan_pricing)

        self.assertInHTML(
            '<div class="pricing-plans-price__price jsPricingPlansCardPriceWhole">10</div>',
            rendered_html,
        )
        self.assertIn('data-amount="10.00"', rendered_html)
        self.assertIn('data-renewal="True"', rendered_html)

    def test_non_recurring_plan(self):
        self.plan_pricing.has_automatic_renewal = False
        self.plan_pricing.save()

        rendered_html = self.render_widget(self.plan_pricing)

        self.assertIn('<input type="radio" name="plan_choice"', rendered_html)

When I look at the coverage it shows 0% for this template although lines from plans/plan_choice_widget.html template are matched by the tests.

My .coveragerc:

[run]
omit =
   */virtualenvs/*
   */migrations/*
   */site-packages/*
   *.txt
   */settings/dev.py
plugins =
    django_coverage_plugin
branch = True
source = blenderhub
relative_files = True

I am using django-coverage-plugin version 3.1.0, coverage version 7.4.1.

More widget templates from my project are not matched.
Is this a known problem or should I gather more information?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with PlanChoiceWidgetTests1.test_plan_choice_widget_render and test_non_recurring_plan, using plans/plan_choice_widget.html and the provided .coveragerc settings. Check whether the template lines appear in the coverage output despite being rendered, and use the reported django-coverage-plugin 3.1.0 and coverage 7.4.1 versions to define the reproducible behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
testing-qa, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.