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.
Suppose that you have something like the following in your Pytest config:
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 there.escape()
d version as a fix.