PyCQA / flake8-bugbear

A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

B017 support the matches keyword argument to pytest.raises

toofar opened this issue · comments

commented

#317 added support for warning about B017 when using pytest.raises(Exception), and it included an exception for passing a regex to match against similar to unittest.assertRaisesRegex. But you can pass that regex as a keyword argument too and that exception doesn't apply in that case.

Docs with an example of passing the match keyword: https://docs.pytest.org/en/7.1.x/how-to/assert.html#assertions-about-expected-exceptions

Reproducer:

import pytest


def test_positional_arg():
    with pytest.raises(Exception, 'some-regex'):  # this is fine
        pass


def test_keyword_arg():
    with pytest.raises(Exception, match='some-regex'):  # this gets a B017 warning
        pass