flake8-bugbear
flake8-bugbear copied to clipboard
Extend B017 to pytest.raises
with pytest.raises(Exception):
is very similar to assertRaises
, and all the justification of B017 applies to that too.
Sounds reasonable. Unit-tested adding to B017 will be merged.
I have a case where I use:
with pytest.raises(Exception, match='Parsing error'):
call_my_func()
Currently, B017 catches this as a problematic but I have a valid match
here which catches a very specific error message
I still feel it's a good practice to subclass Exception here too ...
If someone wants to add if match=
is passed to not error, we can ...
The error currently says Either assert for a more specific exception (builtin or custom), use assertRaisesRegex, or use the context manager form of assertRaises.
Which I assume refers to the unittest functions. But, it'd be weird to suggest using assertRaisesRegex() and then say that match
is not allowed.
I have a case where I use:
with pytest.raises(Exception, match='Parsing error'): call_my_func()
Currently, B017 catches this as a problematic but I have a valid
match
here which catches a very specific error message
@AbdealiLoKo As a workaround, you can use https://github.com/m-burst/flake8-pytest-style/blob/master/docs/rules/PT011.md to catch that.
Sure thanks @mrcljx will take a look.
Appears this has been resolved (probably someone forgot the 'fixes' in a PR?).
Yup. This is all done. Thanks for the nudge.
FWIW - I dislike using assertRaisesRegex
too, just make a custom exception type. I do accept there are edge cases where you're testing something you can't easily change etc. etc.