populse / soma-base

Miscelaneous all-purpose classes and functions
0 stars 3 forks source link

B017 `assertRaises(Exception)` should be considered evil #67

Closed DimitriPapadopoulos closed 6 months ago

DimitriPapadopoulos commented 6 months ago

https://github.com/populse/soma-base/blob/51191238ee995a7b0863e4b7372bb8060cecb8b9/python/soma/controller/tests/test_controller.py#L1087

https://docs.astral.sh/ruff/rules/assert-raises-exception/

These forms catch every Exception, which can lead to tests passing even if, e.g., the code under consideration raises a SyntaxError or IndentationError.

Either assert for a more specific exception (builtin or custom), or use assertRaisesRegex or pytest.raises(..., match=<REGEX>) respectively.