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

Fix pytest-raises-too-broad (PT011) to flag pytest.raises call with keyword expected_exception #14298

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

harupy
Copy link
Contributor

@harupy harupy commented Nov 12, 2024

Summary

pytest-raises-too-broad (PT011) should be raised when expected_exception is provided as a keyword argument.

def test_foo():
    with pytest.raises(ValueError):  # raises PT011
        raise ValueError("Can't divide 1 by 0")

    # This is minor but a valid pytest.raises call
    with pytest.raises(expected_exception=ValueError):  # doesn't raise PT011 but should
        raise ValueError("Can't divide 1 by 0")

pytest.raises doc: https://docs.pytest.org/en/8.3.x/reference/reference.html#pytest.raises

Test Plan

Unit tests

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@harupy harupy changed the title Fix pytest-raises-too-broad (PT011) to cover expected_exception Fix pytest-raises-too-broad (PT011) to flag pytest.raises with keyword expected_exception Nov 12, 2024
@harupy harupy changed the title Fix pytest-raises-too-broad (PT011) to flag pytest.raises with keyword expected_exception Fix pytest-raises-too-broad (PT011) to flag pytest.raises call with keyword expected_exception Nov 12, 2024
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@charliermarsh charliermarsh added the bug Something isn't working label Nov 12, 2024
@charliermarsh charliermarsh merged commit 2b6d66b into astral-sh:main Nov 12, 2024
20 checks passed
@harupy harupy deleted the PT011-expected_exception branch November 12, 2024 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants