Skip to content

B017 support the matches keyword argument to pytest.raises #334

@toofar

Description

@toofar

#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions