Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ impl Violation for PytestFixtureFinalizerCallback {
/// return resource
/// ```
///
/// ## Fix safety
///
/// This rule's fix is always marked unsafe because removing the `yield` can change the behavior of
/// code that relies on implicit cleanup, such as when a value is garbage-collected.
///
/// ## References
/// - [`pytest` documentation: Teardown/Cleanup](https://docs.pytest.org/en/latest/how-to/fixtures.html#teardown-cleanup-aka-fixture-finalization)
#[derive(ViolationMetadata)]
Expand Down Expand Up @@ -840,9 +845,9 @@ fn check_fixture_returns(checker: &Checker, name: &str, body: &[Stmt], returns:
))
});
if let Some(return_type_edit) = return_type_edit {
diagnostic.set_fix(Fix::safe_edits(yield_edit, [return_type_edit]));
diagnostic.set_fix(Fix::unsafe_edits(yield_edit, [return_type_edit]));
} else {
diagnostic.set_fix(Fix::safe_edit(yield_edit));
diagnostic.set_fix(Fix::unsafe_edit(yield_edit));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ help: Replace `yield` with `return`
17 + return resource
18 |
|
note: This is an unsafe fix and may change runtime behavior

PT022 [*] No teardown in fixture `error`, use `return` instead of `yield`
--> PT022.py:37:5
Expand All @@ -33,6 +34,7 @@ help: Replace `yield` with `return`
37 + return resource
38 |
|
note: This is an unsafe fix and may change runtime behavior

PT022 [*] No teardown in fixture `error`, use `return` instead of `yield`
--> PT022.py:43:5
Expand All @@ -50,3 +52,4 @@ help: Replace `yield` with `return`
- yield resource
43 + return resource
|
note: This is an unsafe fix and may change runtime behavior
Loading