Skip to content

Readme rule examples are inverted #187

Open
@edmorley

Description

@edmorley

I just tried to use coverage-conditional-plugin by following the README, however pytest-cov was still reporting less than 100% coverage.

After going down a rabbit hole of thinking that my pyproject.toml settings weren't being picked up (eg the plugin not being activated, or similar), I discovered that the cause was that my pragma rules were inverted.

I'd used:

if sys.version_info < (3, 11):
    import tomli as tomllib  # pragma: py-lt-311
else:
    import tomllib  # pragma: py-gte-311

Instead of:

if sys.version_info < (3, 11):
    import tomli as tomllib  # pragma: py-gte-311
else:
    import tomllib  # pragma: py-lt-311

I only discovered this by chance, after seeing:
#179 (comment)

I'd followed the docs, however they appear to have the example inverted too:

## Example
Imagine that we have this code:
```python
try: # pragma: has-django
import django
except ImportError: # pragma: has-no-django
django = None
def run_if_django_is_installed():
if django is not None: # pragma: has-django
...
```
And here's the configuration you might use:
```ini
[coverage:coverage_conditional_plugin]
rules =
"is_installed('django')": has-django
"not is_installed('django')": has-no-django
```

In addition to fixing this example, maybe it's worth adding the `pragma: some` means `pragma: no cover if some` explanation to the README too? (Given I'm not the first person to be confused about this, given #179 etc) :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions