pytest-dev / pytest-dev/pytest
Warn on impossible-to-match message pattern in filterwarnings - likely user error
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Suppose that you have something like the following in your Pytest config:
filterwarnings =
ignore::The foo.bar() function is deprecated
This looks perfectly reasonable, but somehow the warning still occurs! Unfortunately - and this got me recently - the message argument is a regex pattern, and in that context the parens () are an empty group... meaning that it won't match a string which contains the literal parentheses.
I think we should use the re._parse (sre_parse on older Pythons) module to check whether filterwarnings patterns contain an empty match. Since there's no use for capture groups, it's very likely that the pattern was intended as a literal string or prefix. This is pretty easy to get wrong if you're copy-pasting the message into your warnings config! We can even suggest the re.escape()d version as a fix.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating pytest's filterwarnings parsing and reviewing how the message pattern is compiled. Investigate re._parse, or sre_parse on older Python versions, and add tests covering the shown unescaped pattern. Done means impossible-to-match patterns receive a clear diagnostic, with an escaped alternative if appropriate, and the tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100