-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ruff
] Ambiguous pattern passed to pytest.raises()
(RUF043
)
#14966
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aa7c080
[`flake8-pytest-style`] Ambiguous pattern passed to `pytest.raises()`…
InSyncWithFoo f678f51
Clippy
InSyncWithFoo 9a79951
Fix
InSyncWithFoo b09ce9e
Per review
InSyncWithFoo f9fd560
Also ignore manually escaped patterns
InSyncWithFoo 357e189
Also detect metasequences
InSyncWithFoo 12b021a
Revert changes made to `unnecessary_regular_expression.rs`
InSyncWithFoo 3a103a0
Recode to `RUF043`
InSyncWithFoo 97f3aa9
Simplifications from Micha
AlexWaygood 4eca697
micronits
AlexWaygood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT201.py
InSyncWithFoo marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import re | ||
import pytest | ||
|
||
def test_foo(): | ||
|
||
### Errors | ||
|
||
with pytest.raises(FooAtTheEnd, match="foo."): ... | ||
with pytest.raises(PackageExtraSpecifier, match="Install `foo[bar]` instead"): ... | ||
with pytest.raises(InnocentQuestion, match="This is a simple sentence (or is it?)"): ... | ||
|
||
with pytest.raises(ManuallyEscapedWindowsPathToDotFile, match="C:\\\\Users\\\\Foo\\\\.config"): ... | ||
|
||
with pytest.raises(MiddleDot, match="foo.bar"): ... | ||
with pytest.raises(EndDot, match="foobar."): ... | ||
with pytest.raises(EndBackslash, match="foobar\\"): ... | ||
|
||
|
||
### No errors | ||
|
||
with pytest.raises(NoMatch): ... | ||
with pytest.raises(NonLiteral, match=pattern): ... | ||
with pytest.raises(FunctionCall, match=frobnicate("qux")): ... | ||
with pytest.raises(ReEscaped, match=re.escape("foobar")): ... | ||
with pytest.raises(RawString, match=r"fo()bar"): ... | ||
with pytest.raises(RawStringPart, match=r"foo" '\bar'): ... | ||
with pytest.raises(NoMetacharacters, match="foobar"): ... | ||
|
||
with pytest.raises(ManuallyEscaped, match="some\\.fully\\.qualified\\.name"): ... | ||
with pytest.raises(ManuallyEscapedWindowsPath, match="C:\\\\Users\\\\Foo\\\\file\\.py"): ... | ||
|
||
with pytest.raises(MiddleEscapedDot, match="foo\\.bar"): ... | ||
with pytest.raises(MiddleEscapedBackslash, match="foo\\\\bar"): ... | ||
with pytest.raises(EndEscapedDot, match="foobar\\."): ... | ||
with pytest.raises(EndEscapedBackslash, match="foobar\\\\"): ... |
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
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
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
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
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
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
74 changes: 74 additions & 0 deletions
74
...le/snapshots/ruff_linter__rules__flake8_pytest_style__tests__preview__PT201_PT201.py.snap
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs | ||
snapshot_kind: text | ||
--- | ||
PT201.py:8:43: PT201 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw | ||
| | ||
6 | ### Errors | ||
7 | | ||
8 | with pytest.raises(FooAtTheEnd, match="foo."): ... | ||
| ^^^^^^ PT201 | ||
9 | with pytest.raises(PackageExtraSpecifier, match="Install `foo[bar]` instead"): ... | ||
10 | with pytest.raises(InnocentQuestion, match="This is a simple sentence (or is it?)"): ... | ||
| | ||
= help: Use a raw string or `re.escape()` to make the intention explicit | ||
|
||
PT201.py:9:53: PT201 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw | ||
| | ||
8 | with pytest.raises(FooAtTheEnd, match="foo."): ... | ||
9 | with pytest.raises(PackageExtraSpecifier, match="Install `foo[bar]` instead"): ... | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT201 | ||
10 | with pytest.raises(InnocentQuestion, match="This is a simple sentence (or is it?)"): ... | ||
| | ||
= help: Use a raw string or `re.escape()` to make the intention explicit | ||
|
||
PT201.py:10:48: PT201 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw | ||
| | ||
8 | with pytest.raises(FooAtTheEnd, match="foo."): ... | ||
9 | with pytest.raises(PackageExtraSpecifier, match="Install `foo[bar]` instead"): ... | ||
10 | with pytest.raises(InnocentQuestion, match="This is a simple sentence (or is it?)"): ... | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT201 | ||
11 | | ||
12 | with pytest.raises(ManuallyEscapedWindowsPathToDotFile, match="C:\\\\Users\\\\Foo\\\\.config"): ... | ||
| | ||
= help: Use a raw string or `re.escape()` to make the intention explicit | ||
|
||
PT201.py:12:67: PT201 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw | ||
| | ||
10 | with pytest.raises(InnocentQuestion, match="This is a simple sentence (or is it?)"): ... | ||
11 | | ||
12 | with pytest.raises(ManuallyEscapedWindowsPathToDotFile, match="C:\\\\Users\\\\Foo\\\\.config"): ... | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT201 | ||
13 | | ||
14 | with pytest.raises(MiddleDot, match="foo.bar"): ... | ||
| | ||
= help: Use a raw string or `re.escape()` to make the intention explicit | ||
|
||
PT201.py:14:41: PT201 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw | ||
| | ||
12 | with pytest.raises(ManuallyEscapedWindowsPathToDotFile, match="C:\\\\Users\\\\Foo\\\\.config"): ... | ||
13 | | ||
14 | with pytest.raises(MiddleDot, match="foo.bar"): ... | ||
| ^^^^^^^^^ PT201 | ||
15 | with pytest.raises(EndDot, match="foobar."): ... | ||
16 | with pytest.raises(EndBackslash, match="foobar\\"): ... | ||
| | ||
= help: Use a raw string or `re.escape()` to make the intention explicit | ||
|
||
PT201.py:15:38: PT201 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw | ||
| | ||
14 | with pytest.raises(MiddleDot, match="foo.bar"): ... | ||
15 | with pytest.raises(EndDot, match="foobar."): ... | ||
| ^^^^^^^^^ PT201 | ||
16 | with pytest.raises(EndBackslash, match="foobar\\"): ... | ||
| | ||
= help: Use a raw string or `re.escape()` to make the intention explicit | ||
|
||
PT201.py:16:44: PT201 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw | ||
| | ||
14 | with pytest.raises(MiddleDot, match="foo.bar"): ... | ||
15 | with pytest.raises(EndDot, match="foobar."): ... | ||
16 | with pytest.raises(EndBackslash, match="foobar\\"): ... | ||
| ^^^^^^^^^^ PT201 | ||
| | ||
= help: Use a raw string or `re.escape()` to make the intention explicit |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.