Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ def check_for_b017(self, node):
item = node.items[0]
item_context = item.context_expr
if (
hasattr(item_context.func, "attr")
hasattr(item_context, "func")
and hasattr(item_context.func, "attr") # noqa W503
and item_context.func.attr == "assertRaises" # noqa W503
and len(item_context.args) == 1 # noqa W503
and item_context.args[0].id == "Exception" # noqa W503
Expand Down
8 changes: 8 additions & 0 deletions tests/b017.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
import unittest


CONSTANT = True


def something_else() -> None:
for i in (1, 2, 3):
print(i)


class Foobar(unittest.TestCase):
def evil_raises(self) -> None:
with self.assertRaises(Exception):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_b017(self):
filename = Path(__file__).absolute().parent / "b017.py"
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())
expected = self.errors(B017(10, 8))
expected = self.errors(B017(18, 8))
self.assertEqual(errors, expected)

def test_b301_b302_b305(self):
Expand Down