Skip to content

Ignore exclusions inside multiline strings#2180

Open
puneetdixit200 wants to merge 7 commits into
coveragepy:mainfrom
puneetdixit200:fix-ellipsis-string-exclusion
Open

Ignore exclusions inside multiline strings#2180
puneetdixit200 wants to merge 7 commits into
coveragepy:mainfrom
puneetdixit200:fix-ellipsis-string-exclusion

Conversation

@puneetdixit200

Copy link
Copy Markdown

Summary:

  • prevent exclusion regex matches inside string tokens from excluding the containing statement
  • add regression tests for YAML-style multiline literals and single-line string literals containing ...
  • keep real pragma comments on string assignment lines covered

Tests:

  • PYTHONWARNDEFAULTENCODING= /tmp/coveragepy-venv/bin/python -m pytest -q tests/test_coverage.py::ExcludeTest::test_default_ellipsis_exclusion_ignores_multiline_strings tests/test_coverage.py::ExcludeTest::test_default tests/test_parser.py::ExclusionParserTest::test_over_exclusion_bug1779
  • PYTHONWARNDEFAULTENCODING= /tmp/coveragepy-venv/bin/python -m pytest -q tests/test_coverage.py::ExcludeTest
  • PYTHONWARNDEFAULTENCODING= /tmp/coveragepy-venv/bin/python -m pytest -q tests/test_parser.py::ExclusionParserTest
  • /tmp/coveragepy-venv/bin/python -m compileall -q coverage/parser.py tests/test_coverage.py
  • git diff --check

Supersedes #2177
Fixes #2112

Add explicit coverage showing default ellipsis exclusion patterns inside single-line strings are ignored while real pragma comments on the same line still exclude.
Comment thread coverage/parser.py
ltext,
)
)
if toktype == token.STRING and slineno != elineno:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right to me: This is saying that any lines that are part of a multi-line string won't be excluded. That's not taking into account what else is on those lines, or whether the multi-line string matched one of the exclusion rules.

For example, this test fails:

        self.check_coverage(
            """\
            a = 1
            ignore_var = "2"
            ignore_var = '''
                3,4,5
                '''
            ignore_var = "6"
            a = 7
            """,
            excludes=["ignore_var"],
            lines=[1, 7],
        )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this as a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default ... exclusion can exclude things by accident

2 participants