3

Assume I have the following __init__py:

# __init__.py
from . import my_foo

Just like so, flake8 would complain with F401. This can be resolved by:

# __init__.py
from . import my_foo  # NOQA: F401

On the other hand, cov plugin of pytest would complain that there are no tests for this line. This can be resolved by:

# __init__.py
from . import my_foo  # pragma: no cover

How can I make both happy? I could do something like:

# flake8: noqa
from . import gender  # pragma: no cover

But this influences the whole file from flake8's perspective.

I also tried something like:

from . import gender  # pragma: no cover, NOQA: F401

But it didn't work as expected.

Dror
  • 12,174
  • 21
  • 90
  • 160

1 Answers1

5

The comment syntax for coverage.py is configurable. You can override the regexes that lines are matched against: Advanced Exclusion

For example:

[report]
exclude_lines =
    pragma: no cover

This will match any line containing "pragma: no cover", so this comment should now work:

# NOQA: F401; pragma: no cover

The default regex requires only space between the "#" and "pragma"

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662