Skip to content

Rule E712 in pytest assertion #18272

@EricDepagne

Description

@EricDepagne

Summary

I do some image analysis and I have some pytests that use assert().

Here's an example:

def test_blurry(not_blurry_image):
    assert is_blurry(not_blurry_image) == False

where is_blurry is my function that tests for blurryness and it returns a boolean.
My test is here to make sure that if I pass an image that I know is not blurry to my function it returns False.
And I have a warning from ruff about E712, which is:
Avoid equality comparisons to False; use if not is_blurry(no_blurry_image): for False checks

Not sure if it's my test that should be re-written or if ruff should not trigger this warning in an assert, but the explanation message here is incorrect as I can't use an if statement there.

Version

ruff 0.9.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.help wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions