coveragepy / coveragepy/django_coverage_plugin

Plugin will be disabled due to exception when extra engine is not django.template.backends.django.DjangoTemplates

Open
#101 0 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

When multiple template engines are used, django_coverage_plugin will check them all and raise DjangoTemplatePluginException which will cause it to be disabled by coverage. Instead, it should work for the DjangoTemplates engine and ignore the others.

SETTINGS.PY
TEMPLATES = [
    {
        # https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        # https://docs.djangoproject.com/en/dev/ref/settings/#dirs
        "DIRS": [str(APPS_DIR / "templates")],
        # https://docs.djangoproject.com/en/dev/ref/settings/#app-dirs
        "APP_DIRS": True,
        "OPTIONS": {
            # https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
            ],
            "builtins": ["template_partials.templatetags.partials"],
        },
    },
    {
        "BACKEND": "post_office.template.backends.post_office.PostOfficeTemplates",
        "APP_DIRS": True,
        "DIRS": [],
        "OPTIONS": {
            "context_processors": [
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.debug",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.template.context_processors.request",
            ],
        },
    },
]
TRACEBACK

/tmp/poetry_cache/virtualenvs/.venv/lib/python3.12/site-packages/coverage/inorout.py:378: CoverageWarning: Disabling plug-in 'django_coverage_plugin.DjangoTemplatePlugin' due to an exception:
Traceback (most recent call last):
File "/tmp/poetry_cache/virtualenvs/.venv/lib/python3.12/site-packages/coverage/inorout.py", line 363, in should_trace
file_tracer = plugin.file_tracer(canonical)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/poetry_cache/virtualenvs/.venv/lib/python3.12/site-packages/django_coverage_plugin/plugin.py", line 181, in file_tracer
self.debug_checked = check_debug()
^^^^^^^^^^^^^
File "/tmp/poetry_cache/virtualenvs/.venv/lib/python3.12/site-packages/django_coverage_plugin/plugin.py", line 88, in check_debug
raise DjangoTemplatePluginException(
django_coverage_plugin.plugin.DjangoTemplatePluginException: Can't use non-Django templates.

self.warn(f"Disabling plug-in {plugin_name!r} due to an exception:\n{tb}")

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

Read django_coverage_plugin/plugin.py, starting with file_tracer and check_debug, to see how multiple configured template engines are handled. Done means the DjangoTemplates engine remains supported while non-Django template engines are ignored without disabling the plugin; the payload does not name a test file.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.