Repository navigation
[ruff] Avoid false positive when pytest.raises is used in a with statement (RUF061) - #28186
Merged
ntBre merged 4 commits intoOct 2, 2026
Conversation
…` statement (`RUF061`) Closes astral-sh#28146.
|
ruff] Avoid false positive when pytest.raises is used in a with statement (RUF061)
ntBre
approved these changes
Oct 2, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thanks! I just trimmed down the tests a bit and moved to our new mdtest framework, but the code change looks good to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #28146.
Avoids false-positive
RUF061violations whenpytest.raises(...),pytest.warns(...), orpytest.deprecated_call(...)is already used as the context expression in awith(orasync with) statement.Previously, passing additional positional arguments (such as
with pytest.raises(ValueError, "oops"):) causedfind_argument("func", 1)to match the second positional argument as the deprecated callable parameter, triggeringRUF061on code that was already using context-manager syntax.Test Plan
RUF061_raises.py,RUF061_warns.py, andRUF061_deprecated_call.pywith test cases covering extra positional arguments inwithstatements and nested calls withinwithbodies.INSTA_UPDATE=always cargo test -p ruff_linter.cargo fmt --checkandcargo clippy -p ruff_linter --all-targets.