Conversation
4 tasks done
ntBre
pushed a commit
to astral-sh/ruff
that referenced
this pull request
Jun 16, 2025
…t.warns`, and `pytest.deprecated_call` (`RUF061`) (#17368) <!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> This PR aims to close #16605. ## Summary This PR introduces a new rule (`RUF061`) that detects non-contextmanager usage of `pytest.raises`, `pytest.warns`, and `pytest.deprecated_call`. This pattern is discouraged and [was proposed in flake8-pytest-style](m-burst/flake8-pytest-style#332), but the corresponding PR has been open for over a month without activity. Additionally, this PR provides an unsafe fix for simple cases where the non-contextmanager form can be transformed into the context manager form. Examples of supported patterns are listed in `RUF061_raises.py`, `RUF061_warns.py`, and `RUF061_deprecated_call.py` test files. The more complex case from the original issue (involving two separate statements): ```python excinfo = pytest.raises(ValueError, int, "hello") assert excinfo.match("^invalid literal") ``` is getting fixed like this: ```python with pytest.raises(ValueError) as excinfo: int("hello") assert excinfo.match("^invalid literal") ``` Putting match in the raises call requires multi-statement transformation, which I am not sure how to implement. ## Test Plan <!-- How was it tested? --> New test files were added to cover various usages of the non-contextmanager form of pytest.raises, warns, and deprecated_call.
KotlinIsland
pushed a commit
to KotlinIsland/basedpython
that referenced
this pull request
May 1, 2026
…t.warns`, and `pytest.deprecated_call` (`RUF061`) (#17368) <!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> This PR aims to close #16605. ## Summary This PR introduces a new rule (`RUF061`) that detects non-contextmanager usage of `pytest.raises`, `pytest.warns`, and `pytest.deprecated_call`. This pattern is discouraged and [was proposed in flake8-pytest-style](m-burst/flake8-pytest-style#332), but the corresponding PR has been open for over a month without activity. Additionally, this PR provides an unsafe fix for simple cases where the non-contextmanager form can be transformed into the context manager form. Examples of supported patterns are listed in `RUF061_raises.py`, `RUF061_warns.py`, and `RUF061_deprecated_call.py` test files. The more complex case from the original issue (involving two separate statements): ```python excinfo = pytest.raises(ValueError, int, "hello") assert excinfo.match("^invalid literal") ``` is getting fixed like this: ```python with pytest.raises(ValueError) as excinfo: int("hello") assert excinfo.match("^invalid literal") ``` Putting match in the raises call requires multi-statement transformation, which I am not sure how to implement. ## Test Plan <!-- How was it tested? --> New test files were added to cover various usages of the non-contextmanager form of pytest.raises, warns, and deprecated_call.
MichaelOultram-pexip
pushed a commit
to pexip/os-ruff
that referenced
this pull request
Aug 28, 2026
…t.warns`, and `pytest.deprecated_call` (`RUF061`) (#17368) <!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> This PR aims to close #16605. ## Summary This PR introduces a new rule (`RUF061`) that detects non-contextmanager usage of `pytest.raises`, `pytest.warns`, and `pytest.deprecated_call`. This pattern is discouraged and [was proposed in flake8-pytest-style](m-burst/flake8-pytest-style#332), but the corresponding PR has been open for over a month without activity. Additionally, this PR provides an unsafe fix for simple cases where the non-contextmanager form can be transformed into the context manager form. Examples of supported patterns are listed in `RUF061_raises.py`, `RUF061_warns.py`, and `RUF061_deprecated_call.py` test files. The more complex case from the original issue (involving two separate statements): ```python excinfo = pytest.raises(ValueError, int, "hello") assert excinfo.match("^invalid literal") ``` is getting fixed like this: ```python with pytest.raises(ValueError) as excinfo: int("hello") assert excinfo.match("^invalid literal") ``` Putting match in the raises call requires multi-statement transformation, which I am not sure how to implement. ## Test Plan <!-- How was it tested? --> New test files were added to cover various usages of the non-contextmanager form of pytest.raises, warns, and deprecated_call.
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.
fixes #331
code, test & docs should be fairly self-explanatory