---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B017 Do not assert blind exception: `Exception`
  --> B017_0.py:23:14
   |
21 | class Foobar(unittest.TestCase):
22 |     def evil_raises(self) -> None:
23 |         with self.assertRaises(Exception):
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24 |             raise Exception("Evil I say!")
   |

B017 Do not assert blind exception: `BaseException`
  --> B017_0.py:27:14
   |
26 |     def also_evil_raises(self) -> None:
27 |         with self.assertRaises(BaseException):
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28 |             raise Exception("Evil I say!")
   |

B017 Do not assert blind exception: `Exception`
  --> B017_0.py:45:10
   |
44 | def test_pytest_raises():
45 |     with pytest.raises(Exception):
   |          ^^^^^^^^^^^^^^^^^^^^^^^^
46 |         raise ValueError("Hello")
   |

B017 Do not assert blind exception: `Exception`
  --> B017_0.py:48:10
   |
46 |         raise ValueError("Hello")
47 |
48 |     with pytest.raises(Exception), pytest.raises(ValueError):
   |          ^^^^^^^^^^^^^^^^^^^^^^^^
49 |         raise ValueError("Hello")
   |

B017 Do not assert blind exception: `Exception`
  --> B017_0.py:57:36
   |
55 |         raise ValueError("This is also fine")
56 |
57 |     with contextlib.nullcontext(), pytest.raises(Exception):
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^
58 |         raise ValueError("Multiple context managers")
   |

B017 Do not assert blind exception: `Exception`
  --> B017_0.py:62:10
   |
61 | def test_pytest_raises_keyword():
62 |     with pytest.raises(expected_exception=Exception):
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63 |         raise ValueError("Should be flagged")
   |

B017 Do not assert blind exception: `Exception`
  --> B017_0.py:68:18
   |
66 |     class TestKwargs(unittest.TestCase):
67 |         def test_method(self):
68 |             with self.assertRaises(exception=Exception):
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69 |                 raise ValueError("Should be flagged")
   |

B017 Do not assert blind exception: `BaseException`
  --> B017_0.py:71:18
   |
69 |                 raise ValueError("Should be flagged")
70 |
71 |             with self.assertRaises(exception=BaseException):
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72 |                 raise ValueError("Should be flagged")
   |
