Skip to content

detect if a regex escape is needed in a pytest match statement #13705

@nstarman

Description

@nstarman

Sometimes re.escape are needed in pytest for match=... arguments.
Then the string is modified and the regex escape is no longer needed.
It would be great if ruff could detect this and remove the unneeded re.escape.

M~WE:

import pytest, re

with pytest.raises(Exception, match=re.escape("regexnotneeded")):
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions