Fixed invalid regex handling in filterwarnings#13124
Fixed invalid regex handling in filterwarnings#13124graingert merged 16 commits intopytest-dev:mainfrom
Conversation
The-Compiler
left a comment
There was a problem hiding this comment.
Nice! Definitely much better. New output (with my small suggestion added):
ERROR: while parsing the following warning configuration:
ignore::DeprecationWarning:*
This error occurred:
Invalid regex '*': nothing to repeat at position 0
…com/virendrapatil24/pytest into fix-invalid-regex-in-filterwarnings
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
testing/test_warnings.py
Outdated
| result = pytester.runpytest_subprocess() | ||
| result.stderr.fnmatch_lines( | ||
| [ | ||
| "*Invalid regex '*': nothing to repeat at position 0*", |
There was a problem hiding this comment.
I think it would be more thorough to test on the whole "while parsing ..." output?
|
it looks like there's no tests for "invalid lineno (negative AND not an integer)", too many fields, invalid action or resolving the warning category perhaps you'd be interested in adding these tests? Should be very similar to test_invalid_regex_in_filterwarning perhaps in this PR or perhaps in a followup? |
|
Thanks for the review! I’m a bit confused about what else is required for this PR. Could you summarize the key changes you’d like to see here? From my understanding, the missing tests you mentioned might be better suited for a follow-up rather than this ticket. Let me know your thoughts! |
So yeah could you:
|
sure will make those asserts, thanks for clarifying. |
testing/test_warnings.py
Outdated
| "", | ||
| "This error occurred:", | ||
| "", | ||
| "Invalid regex '*': nothing to repeat at position 0", |
There was a problem hiding this comment.
I think you need to escape this star or it will treat it as a wildcard/fnmatch syntax. I'm not sure how to escape it though
| "Invalid regex '*': nothing to repeat at position 0", | |
| r"Invalid regex '\*': nothing to repeat at position 0", |
There was a problem hiding this comment.
makes sense, I will check what I can do here.
There was a problem hiding this comment.
we can escape * using [*]
ref: https://docs.python.org/3/library/fnmatch.html
closes #13119
parse_warning_filtermethod to handle invalid regex pattern provided to message/module args.