Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme rule examples are inverted #187

Open
edmorley opened this issue Dec 22, 2022 · 0 comments
Open

Readme rule examples are inverted #187

edmorley opened this issue Dec 22, 2022 · 0 comments

Comments

@edmorley
Copy link

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) :-)

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

No branches or pull requests

1 participant