Add pragma: no cover implementation#110
Open
marcgibbons wants to merge 5 commits intocoveragepy:mainfrom
Open
Conversation
Tests cover block-tag exclusion (with both true/false conditions),
plain text line exclusion, nested block exclusion, custom exclude
patterns via coverage config, and self-closing tags like {% cycle %}
that should not be treated as block openers.
Allow users to exclude template lines from coverage using Django comment syntax. A pragma on a block-opening tag excludes the entire block (including nested blocks) through its matching closing tag. A pragma on a plain text or variable line excludes that line only. Uses coverage.py's report:exclude_lines patterns, so the default pragma: no cover works with zero configuration and custom patterns defined in .coveragerc / pyproject.toml are picked up automatically. Block openers are identified by a forward look-ahead for a matching end tag, so self-closing tags like cycle, load, and url are never mistakenly treated as block openers.
4525646 to
cff82b6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements
pragma: no coverfor templates. I tried to mirror the same behaviour used in Python; when declared on a block, the entire block is excluded. When declared on a single line / not a block tag, only that line is excluded. The implementation supports theexclude_linesandexclude_alsocoverage.py report settings.Example:
I tried keeping iterations to a minimum. I evaluate the tokens as list prior to the for loop to support a lookahead search for nested closing tags.
Fixes #70
Fixes #45