Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
toofar opened this issue Jan 17, 2023 · 0 comments · Fixed by #337
Closed

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

toofar opened this issue Jan 17, 2023 · 0 comments · Fixed by #337

Comments

@toofar
Copy link

toofar commented Jan 17, 2023

#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
nsoranzo added a commit to nsoranzo/flake8-bugbear that referenced this issue Jan 18, 2023
Fix PyCQA#334 .

Also add more tests for when we should and shouldn't emit B017.
In particular we should check ``assertRaises`` and ``pytest.raises``
calls outside of with statements.
nsoranzo added a commit to nsoranzo/flake8-bugbear that referenced this issue Jan 19, 2023
Fix PyCQA#334 .

Also add more tests for when we should and shouldn't emit B017.
In particular we should check ``assertRaises`` and ``pytest.raises``
calls outside of with statements.
cooperlees pushed a commit that referenced this issue Jan 19, 2023
)

Fix #334 .

Also add more tests for when we should and shouldn't emit B017.
In particular we should check ``assertRaises`` and ``pytest.raises``
calls outside of with statements.
busgaidw2 added a commit to busgaidw2/flake8-bugbear that referenced this issue Aug 6, 2024
…337)

Fix PyCQA/flake8-bugbear#334 .

Also add more tests for when we should and shouldn't emit B017.
In particular we should check ``assertRaises`` and ``pytest.raises``
calls outside of with statements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant