Skip to content

[flake8-bugbear] B017 does not support non-with calls #19050

@MeGaGiGaGon

Description

@MeGaGiGaGon

Summary

I found this while working on #18972

assert-raises-exception (B017) does not lint on non-with calls, even though both unittest and pytest support them:
https://play.ruff.rs/c875da29-d677-4f97-ad23-2efd2fa88231

import unittest

def func_that_will_raise():
    raise ValueError

class Tests(unittest.TestCase):
    def test_raises(self):
        with self.assertRaises(Exception):  # B017
            func_that_will_raise()
        self.assertRaises(Exception, func_that_will_raise)  # No error


import pytest

def test_raises():
    with pytest.raises(Exception):  # B017
        func_that_will_raise()

pytest.raises(Exception, func_that_will_raise)  # No error

unittest docs on assertRaises
pytest docs on alternate raises form

Version

playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions