Add applicability to flake8_pytest_style (#5389)

This commit is contained in:
Evan Rittenhouse 2023-06-27 11:39:56 -05:00 committed by GitHub
parent 1ed227a1e0
commit 0585e14d3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 48 additions and 64 deletions

View file

@ -200,8 +200,7 @@ pub(crate) fn unittest_assertion(
&& !has_comments_in(expr.range(), checker.locator) && !has_comments_in(expr.range(), checker.locator)
{ {
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) { if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
checker.generator().stmt(&stmt), checker.generator().stmt(&stmt),
expr.range(), expr.range(),
))); )));

View file

@ -295,8 +295,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
&& args.is_empty() && args.is_empty()
&& keywords.is_empty() && keywords.is_empty()
{ {
#[allow(deprecated)] let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
pytest_fixture_parentheses( pytest_fixture_parentheses(
checker, checker,
decorator, decorator,
@ -346,8 +345,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
if checker.enabled(Rule::PytestFixtureIncorrectParenthesesStyle) if checker.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
&& checker.settings.flake8_pytest_style.fixture_parentheses && checker.settings.flake8_pytest_style.fixture_parentheses
{ {
#[allow(deprecated)] let fix = Fix::automatic(Edit::insertion(
let fix = Fix::unspecified(Edit::insertion(
Parentheses::Empty.to_string(), Parentheses::Empty.to_string(),
decorator.end(), decorator.end(),
)); ));
@ -406,8 +404,7 @@ fn check_fixture_returns(checker: &mut Checker, stmt: &Stmt, name: &str, body: &
stmt.range(), stmt.range(),
); );
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)] diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
"return".to_string(), "return".to_string(),
TextRange::at(stmt.start(), "yield".text_len()), 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()); Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, expr.range());
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
let range = checker.locator.full_lines_range(expr.range()); let range = checker.locator.full_lines_range(expr.range());
#[allow(deprecated)] diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
} }
checker.diagnostics.push(diagnostic); checker.diagnostics.push(diagnostic);
} }
@ -499,8 +495,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) {
Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range()); Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range());
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
let line_range = checker.locator.full_lines_range(expr.range()); let line_range = checker.locator.full_lines_range(expr.range());
#[allow(deprecated)] diagnostic.set_fix(Fix::automatic(Edit::range_deletion(line_range)));
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(line_range)));
} }
checker.diagnostics.push(diagnostic); checker.diagnostics.push(diagnostic);
} }

View file

@ -83,15 +83,13 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Decorator, call_pat
&& args.is_empty() && args.is_empty()
&& keywords.is_empty() && keywords.is_empty()
{ {
#[allow(deprecated)] let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
pytest_mark_parentheses(checker, decorator, call_path, fix, "", "()"); pytest_mark_parentheses(checker, decorator, call_path, fix, "", "()");
} }
} }
_ => { _ => {
if checker.settings.flake8_pytest_style.mark_parentheses { if checker.settings.flake8_pytest_style.mark_parentheses {
#[allow(deprecated)] let fix = Fix::automatic(Edit::insertion("()".to_string(), decorator.end()));
let fix = Fix::unspecified(Edit::insertion("()".to_string(), decorator.end()));
pytest_mark_parentheses(checker, decorator, call_path, fix, "()", ""); 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 { if !has_parameters {
let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range()); let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range());
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_deletion(decorator.range())));
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(decorator.range())));
} }
checker.diagnostics.push(diagnostic); checker.diagnostics.push(diagnostic);
} }

View file

@ -163,8 +163,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load, ctx: ExprContext::Load,
range: TextRange::default(), range: TextRange::default(),
}); });
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
format!("({})", checker.generator().expr(&node)), format!("({})", checker.generator().expr(&node)),
name_range, name_range,
))); )));
@ -195,8 +194,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load, ctx: ExprContext::Load,
range: TextRange::default(), range: TextRange::default(),
}); });
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
checker.generator().expr(&node), checker.generator().expr(&node),
name_range, name_range,
))); )));
@ -228,8 +226,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load, ctx: ExprContext::Load,
range: TextRange::default(), range: TextRange::default(),
}); });
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
checker.generator().expr(&node), checker.generator().expr(&node),
expr.range(), expr.range(),
))); )));
@ -245,8 +242,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
); );
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
if let Some(content) = elts_to_csv(elts, checker.generator()) { if let Some(content) = elts_to_csv(elts, checker.generator()) {
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
content, content,
expr.range(), expr.range(),
))); )));
@ -278,8 +274,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load, ctx: ExprContext::Load,
range: TextRange::default(), range: TextRange::default(),
}); });
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
format!("({})", checker.generator().expr(&node)), format!("({})", checker.generator().expr(&node)),
expr.range(), expr.range(),
))); )));
@ -295,8 +290,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
); );
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
if let Some(content) = elts_to_csv(elts, checker.generator()) { if let Some(content) = elts_to_csv(elts, checker.generator()) {
#[allow(deprecated)] diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
content, content,
expr.range(), expr.range(),
))); )));
@ -373,8 +367,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
let node = value.clone(); let node = value.clone();
#[allow(deprecated)] diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
checker.generator().expr(&node), checker.generator().expr(&node),
expr.range(), expr.range(),
))); )));

View file

@ -10,7 +10,7 @@ PT001.py:9:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
| |
= help: Add parentheses = help: Add parentheses
Suggested fix Fix
6 6 | # `import pytest` 6 6 | # `import pytest`
7 7 | 7 7 |
8 8 | 8 8 |
@ -29,7 +29,7 @@ PT001.py:34:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
| |
= help: Add parentheses = help: Add parentheses
Suggested fix Fix
31 31 | # `from pytest import fixture` 31 31 | # `from pytest import fixture`
32 32 | 32 32 |
33 33 | 33 33 |
@ -48,7 +48,7 @@ PT001.py:59:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
| |
= help: Add parentheses = help: Add parentheses
Suggested fix Fix
56 56 | # `from pytest import fixture as aliased` 56 56 | # `from pytest import fixture as aliased`
57 57 | 57 57 |
58 58 | 58 58 |

View file

@ -10,7 +10,7 @@ PT001.py:14:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
| |
= help: Remove parentheses = help: Remove parentheses
Suggested fix Fix
11 11 | return 42 11 11 | return 42
12 12 | 12 12 |
13 13 | 13 13 |
@ -31,7 +31,7 @@ PT001.py:24:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
| |
= help: Remove parentheses = help: Remove parentheses
Suggested fix Fix
21 21 | return 42 21 21 | return 42
22 22 | 22 22 |
23 23 | 23 23 |
@ -52,7 +52,7 @@ PT001.py:39:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
| |
= help: Remove parentheses = help: Remove parentheses
Suggested fix Fix
36 36 | return 42 36 36 | return 42
37 37 | 37 37 |
38 38 | 38 38 |
@ -73,7 +73,7 @@ PT001.py:49:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
| |
= help: Remove parentheses = help: Remove parentheses
Suggested fix Fix
46 46 | return 42 46 46 | return 42
47 47 | 47 47 |
48 48 | 48 48 |
@ -94,7 +94,7 @@ PT001.py:64:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
| |
= help: Remove parentheses = help: Remove parentheses
Suggested fix Fix
61 61 | return 42 61 61 | return 42
62 62 | 62 62 |
63 63 | 63 63 |
@ -115,7 +115,7 @@ PT001.py:74:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
| |
= help: Remove parentheses = help: Remove parentheses
Suggested fix Fix
71 71 | return 42 71 71 | return 42
72 72 | 72 72 |
73 73 | 73 73 |

View file

@ -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 = help: Use a `csv` for parameter names
Suggested fix Fix
26 26 | ... 26 26 | ...
27 27 | 27 27 |
28 28 | 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 = help: Use a `csv` for parameter names
Suggested fix Fix
36 36 | ... 36 36 | ...
37 37 | 37 37 |
38 38 | 38 38 |

View file

@ -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 = help: Use a `csv` for parameter names
Suggested fix Fix
26 26 | ... 26 26 | ...
27 27 | 27 27 |
28 28 | 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 = help: Use a `csv` for parameter names
Suggested fix Fix
36 36 | ... 36 36 | ...
37 37 | 37 37 |
38 38 | 38 38 |

View file

@ -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 = help: Use a `csv` for parameter names
Suggested fix Fix
26 26 | ... 26 26 | ...
27 27 | 27 27 |
28 28 | 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 = help: Use a `csv` for parameter names
Suggested fix Fix
36 36 | ... 36 36 | ...
37 37 | 37 37 |
38 38 | 38 38 |

View file

@ -10,7 +10,7 @@ PT022.py:17:5: PT022 [*] No teardown in fixture `error`, use `return` instead of
| |
= help: Replace `yield` with `return` = help: Replace `yield` with `return`
Suggested fix Fix
14 14 | @pytest.fixture() 14 14 | @pytest.fixture()
15 15 | def error(): 15 15 | def error():
16 16 | resource = acquire_resource() 16 16 | resource = acquire_resource()

View file

@ -10,7 +10,7 @@ PT023.py:12:1: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
| |
= help: Add/remove parentheses = help: Add/remove parentheses
Suggested fix Fix
9 9 | # Without parentheses 9 9 | # Without parentheses
10 10 | 10 10 |
11 11 | 11 11 |
@ -29,7 +29,7 @@ PT023.py:17:1: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
| |
= help: Add/remove parentheses = help: Add/remove parentheses
Suggested fix Fix
14 14 | pass 14 14 | pass
15 15 | 15 15 |
16 16 | 16 16 |
@ -49,7 +49,7 @@ PT023.py:24:5: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
| |
= help: Add/remove parentheses = help: Add/remove parentheses
Suggested fix Fix
21 21 | 21 21 |
22 22 | 22 22 |
23 23 | class TestClass: 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 = help: Add/remove parentheses
Suggested fix Fix
27 27 | 27 27 |
28 28 | 28 28 |
29 29 | class TestClass: 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 = help: Add/remove parentheses
Suggested fix Fix
35 35 | 35 35 |
36 36 | class TestClass: 36 36 | class TestClass:
37 37 | class TestNestedClass: 37 37 | class TestNestedClass:

View file

@ -10,7 +10,7 @@ PT023.py:46:1: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
| |
= help: Add/remove parentheses = help: Add/remove parentheses
Suggested fix Fix
43 43 | # With parentheses 43 43 | # With parentheses
44 44 | 44 44 |
45 45 | 45 45 |
@ -29,7 +29,7 @@ PT023.py:51:1: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
| |
= help: Add/remove parentheses = help: Add/remove parentheses
Suggested fix Fix
48 48 | pass 48 48 | pass
49 49 | 49 49 |
50 50 | 50 50 |
@ -49,7 +49,7 @@ PT023.py:58:5: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
| |
= help: Add/remove parentheses = help: Add/remove parentheses
Suggested fix Fix
55 55 | 55 55 |
56 56 | 56 56 |
57 57 | class TestClass: 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 = help: Add/remove parentheses
Suggested fix Fix
61 61 | 61 61 |
62 62 | 62 62 |
63 63 | class TestClass: 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 = help: Add/remove parentheses
Suggested fix Fix
69 69 | 69 69 |
70 70 | class TestClass: 70 70 | class TestClass:
71 71 | class TestNestedClass: 71 71 | class TestNestedClass:

View file

@ -10,7 +10,7 @@ PT024.py:14:1: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures
| |
= help: Remove `pytest.mark.asyncio` = help: Remove `pytest.mark.asyncio`
Suggested fix Fix
11 11 | pass 11 11 | pass
12 12 | 12 12 |
13 13 | 13 13 |
@ -28,7 +28,7 @@ PT024.py:20:1: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures
| |
= help: Remove `pytest.mark.asyncio` = help: Remove `pytest.mark.asyncio`
Suggested fix Fix
17 17 | return 0 17 17 | return 0
18 18 | 18 18 |
19 19 | 19 19 |
@ -47,7 +47,7 @@ PT024.py:27:1: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures
| |
= help: Remove `pytest.mark.asyncio` = help: Remove `pytest.mark.asyncio`
Suggested fix Fix
24 24 | 24 24 |
25 25 | 25 25 |
26 26 | @pytest.fixture() 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` = help: Remove `pytest.mark.asyncio`
Suggested fix Fix
30 30 | 30 30 |
31 31 | 31 31 |
32 32 | @pytest.fixture() 32 32 | @pytest.fixture()

View file

@ -10,7 +10,7 @@ PT025.py:9:1: PT025 [*] `pytest.mark.usefixtures` has no effect on fixtures
| |
= help: Remove `pytest.mark.usefixtures` = help: Remove `pytest.mark.usefixtures`
Suggested fix Fix
6 6 | pass 6 6 | pass
7 7 | 7 7 |
8 8 | 8 8 |
@ -29,7 +29,7 @@ PT025.py:16:1: PT025 [*] `pytest.mark.usefixtures` has no effect on fixtures
| |
= help: Remove `pytest.mark.usefixtures` = help: Remove `pytest.mark.usefixtures`
Suggested fix Fix
13 13 | 13 13 |
14 14 | 14 14 |
15 15 | @pytest.fixture() 15 15 | @pytest.fixture()