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 false-negative with multiple context managers #13603

Closed
samueljsb opened this issue Oct 2, 2024 · 0 comments · Fixed by #13609
Closed

B017 false-negative with multiple context managers #13603

samueljsb opened this issue Oct 2, 2024 · 0 comments · Fixed by #13609
Labels
bug Something isn't working help wanted Contributions especially welcome

Comments

@samueljsb
Copy link
Contributor

samueljsb commented Oct 2, 2024

$ cat t.py
import contextlib

import pytest

def test_():
    with pytest.raises(Exception):
        pass

    with (
        contextlib.nullcontext(),
        pytest.raises(Exception),
    ):
        pass

$ ruff check --select B017 t.py
t.py:6:10: B017 `pytest.raises(Exception)` should be considered evil
  |
5 | def test_():
6 |     with pytest.raises(Exception):
  |          ^^^^^^^^^^^^^^^^^^^^^^^^ B017
7 |         pass
  |

Found 1 error.

This should report both occurrences of pytest.raises(Exception), but the second one is missing.


$ python --version --version
Python 3.12.5 (v3.12.5:ff3bc82f7c9, Aug  7 2024, 05:32:06) [Clang 13.0.0 (clang-1300.0.29.30)]

$ ruff --version
ruff 0.6.8
@AlexWaygood AlexWaygood added bug Something isn't working help wanted Contributions especially welcome labels Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants