mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
Add applicability to flake8_pytest_style (#5389)
This commit is contained in:
parent
1ed227a1e0
commit
0585e14d3b
14 changed files with 48 additions and 64 deletions
|
@ -200,8 +200,7 @@ pub(crate) fn unittest_assertion(
|
|||
&& !has_comments_in(expr.range(), checker.locator)
|
||||
{
|
||||
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
checker.generator().stmt(&stmt),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -295,8 +295,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
|
|||
&& args.is_empty()
|
||||
&& keywords.is_empty()
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
|
||||
let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
|
||||
pytest_fixture_parentheses(
|
||||
checker,
|
||||
decorator,
|
||||
|
@ -346,8 +345,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
|
|||
if checker.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
|
||||
&& checker.settings.flake8_pytest_style.fixture_parentheses
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::insertion(
|
||||
let fix = Fix::automatic(Edit::insertion(
|
||||
Parentheses::Empty.to_string(),
|
||||
decorator.end(),
|
||||
));
|
||||
|
@ -406,8 +404,7 @@ fn check_fixture_returns(checker: &mut Checker, stmt: &Stmt, name: &str, body: &
|
|||
stmt.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
"return".to_string(),
|
||||
TextRange::at(stmt.start(), "yield".text_len()),
|
||||
)));
|
||||
|
@ -486,8 +483,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) {
|
|||
Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let range = checker.locator.full_lines_range(expr.range());
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -499,8 +495,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) {
|
|||
Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let line_range = checker.locator.full_lines_range(expr.range());
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(line_range)));
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(line_range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -83,15 +83,13 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Decorator, call_pat
|
|||
&& args.is_empty()
|
||||
&& keywords.is_empty()
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
|
||||
let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
|
||||
pytest_mark_parentheses(checker, decorator, call_path, fix, "", "()");
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if checker.settings.flake8_pytest_style.mark_parentheses {
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::insertion("()".to_string(), decorator.end()));
|
||||
let fix = Fix::automatic(Edit::insertion("()".to_string(), decorator.end()));
|
||||
pytest_mark_parentheses(checker, decorator, call_path, fix, "()", "");
|
||||
}
|
||||
}
|
||||
|
@ -114,8 +112,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Decorator, call_
|
|||
if !has_parameters {
|
||||
let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(decorator.range())));
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_deletion(decorator.range())));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -163,8 +163,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
format!("({})", checker.generator().expr(&node)),
|
||||
name_range,
|
||||
)));
|
||||
|
@ -195,8 +194,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
checker.generator().expr(&node),
|
||||
name_range,
|
||||
)));
|
||||
|
@ -228,8 +226,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
checker.generator().expr(&node),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -245,8 +242,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker.generator()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -278,8 +274,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
format!("({})", checker.generator().expr(&node)),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -295,8 +290,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker.generator()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -373,8 +367,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
|
|||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let node = value.clone();
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
checker.generator().expr(&node),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -10,7 +10,7 @@ PT001.py:9:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
|
|||
|
|
||||
= help: Add parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
6 6 | # `import pytest`
|
||||
7 7 |
|
||||
8 8 |
|
||||
|
@ -29,7 +29,7 @@ PT001.py:34:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
|
|||
|
|
||||
= help: Add parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
31 31 | # `from pytest import fixture`
|
||||
32 32 |
|
||||
33 33 |
|
||||
|
@ -48,7 +48,7 @@ PT001.py:59:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
|
|||
|
|
||||
= help: Add parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
56 56 | # `from pytest import fixture as aliased`
|
||||
57 57 |
|
||||
58 58 |
|
||||
|
|
|
@ -10,7 +10,7 @@ PT001.py:14:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
|||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
11 11 | return 42
|
||||
12 12 |
|
||||
13 13 |
|
||||
|
@ -31,7 +31,7 @@ PT001.py:24:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
|||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
21 21 | return 42
|
||||
22 22 |
|
||||
23 23 |
|
||||
|
@ -52,7 +52,7 @@ PT001.py:39:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
|||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
36 36 | return 42
|
||||
37 37 |
|
||||
38 38 |
|
||||
|
@ -73,7 +73,7 @@ PT001.py:49:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
|||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
46 46 | return 42
|
||||
47 47 |
|
||||
48 48 |
|
||||
|
@ -94,7 +94,7 @@ PT001.py:64:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
|||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
61 61 | return 42
|
||||
62 62 |
|
||||
63 63 |
|
||||
|
@ -115,7 +115,7 @@ PT001.py:74:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
|||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
71 71 | return 42
|
||||
72 72 |
|
||||
73 73 |
|
||||
|
|
|
@ -29,7 +29,7 @@ PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
|||
|
|
||||
= help: Use a `csv` for parameter names
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
26 26 | ...
|
||||
27 27 |
|
||||
28 28 |
|
||||
|
@ -67,7 +67,7 @@ PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
|||
|
|
||||
= help: Use a `csv` for parameter names
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
36 36 | ...
|
||||
37 37 |
|
||||
38 38 |
|
||||
|
|
|
@ -67,7 +67,7 @@ PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
|||
|
|
||||
= help: Use a `csv` for parameter names
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
26 26 | ...
|
||||
27 27 |
|
||||
28 28 |
|
||||
|
@ -105,7 +105,7 @@ PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
|||
|
|
||||
= help: Use a `csv` for parameter names
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
36 36 | ...
|
||||
37 37 |
|
||||
38 38 |
|
||||
|
|
|
@ -86,7 +86,7 @@ PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
|||
|
|
||||
= help: Use a `csv` for parameter names
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
26 26 | ...
|
||||
27 27 |
|
||||
28 28 |
|
||||
|
@ -105,7 +105,7 @@ PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
|||
|
|
||||
= help: Use a `csv` for parameter names
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
36 36 | ...
|
||||
37 37 |
|
||||
38 38 |
|
||||
|
|
|
@ -10,7 +10,7 @@ PT022.py:17:5: PT022 [*] No teardown in fixture `error`, use `return` instead of
|
|||
|
|
||||
= help: Replace `yield` with `return`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
14 14 | @pytest.fixture()
|
||||
15 15 | def error():
|
||||
16 16 | resource = acquire_resource()
|
||||
|
|
|
@ -10,7 +10,7 @@ PT023.py:12:1: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
9 9 | # Without parentheses
|
||||
10 10 |
|
||||
11 11 |
|
||||
|
@ -29,7 +29,7 @@ PT023.py:17:1: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
14 14 | pass
|
||||
15 15 |
|
||||
16 16 |
|
||||
|
@ -49,7 +49,7 @@ PT023.py:24:5: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
21 21 |
|
||||
22 22 |
|
||||
23 23 | class TestClass:
|
||||
|
@ -69,7 +69,7 @@ PT023.py:30:5: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
27 27 |
|
||||
28 28 |
|
||||
29 29 | class TestClass:
|
||||
|
@ -90,7 +90,7 @@ PT023.py:38:9: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
35 35 |
|
||||
36 36 | class TestClass:
|
||||
37 37 | class TestNestedClass:
|
||||
|
|
|
@ -10,7 +10,7 @@ PT023.py:46:1: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
43 43 | # With parentheses
|
||||
44 44 |
|
||||
45 45 |
|
||||
|
@ -29,7 +29,7 @@ PT023.py:51:1: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
48 48 | pass
|
||||
49 49 |
|
||||
50 50 |
|
||||
|
@ -49,7 +49,7 @@ PT023.py:58:5: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
55 55 |
|
||||
56 56 |
|
||||
57 57 | class TestClass:
|
||||
|
@ -69,7 +69,7 @@ PT023.py:64:5: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
61 61 |
|
||||
62 62 |
|
||||
63 63 | class TestClass:
|
||||
|
@ -90,7 +90,7 @@ PT023.py:72:9: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
|||
|
|
||||
= help: Add/remove parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
69 69 |
|
||||
70 70 | class TestClass:
|
||||
71 71 | class TestNestedClass:
|
||||
|
|
|
@ -10,7 +10,7 @@ PT024.py:14:1: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures
|
|||
|
|
||||
= help: Remove `pytest.mark.asyncio`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
11 11 | pass
|
||||
12 12 |
|
||||
13 13 |
|
||||
|
@ -28,7 +28,7 @@ PT024.py:20:1: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures
|
|||
|
|
||||
= help: Remove `pytest.mark.asyncio`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
17 17 | return 0
|
||||
18 18 |
|
||||
19 19 |
|
||||
|
@ -47,7 +47,7 @@ PT024.py:27:1: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures
|
|||
|
|
||||
= help: Remove `pytest.mark.asyncio`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
24 24 |
|
||||
25 25 |
|
||||
26 26 | @pytest.fixture()
|
||||
|
@ -66,7 +66,7 @@ PT024.py:33:1: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures
|
|||
|
|
||||
= help: Remove `pytest.mark.asyncio`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
30 30 |
|
||||
31 31 |
|
||||
32 32 | @pytest.fixture()
|
||||
|
|
|
@ -10,7 +10,7 @@ PT025.py:9:1: PT025 [*] `pytest.mark.usefixtures` has no effect on fixtures
|
|||
|
|
||||
= help: Remove `pytest.mark.usefixtures`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
6 6 | pass
|
||||
7 7 |
|
||||
8 8 |
|
||||
|
@ -29,7 +29,7 @@ PT025.py:16:1: PT025 [*] `pytest.mark.usefixtures` has no effect on fixtures
|
|||
|
|
||||
= help: Remove `pytest.mark.usefixtures`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
13 13 |
|
||||
14 14 |
|
||||
15 15 | @pytest.fixture()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue