Files
ruff/docs/rules/assert-raises-exception.md
2023-02-07 18:15:05 -05:00

514 B

assert-raises-exception (B017)

What it does

Checks for the use of assertRaises(Exception).

Why is this bad?

assertRaises(Exception) can lead to your test passing even if the code being tested is never executed (e.g., due to a typo).

Assert for a more specific exception (builtin or custom), use assertRaisesRegex or the context manager form of assertRaises.

Example

self.assertRaises(Exception, foo)

Use instead:

self.assertRaises(SomeSpecificException, foo)