Add PT025 and PT026 docs (#6264)

This commit is contained in:
Harutaka Kawamura 2023-08-03 04:00:03 +09:00 committed by GitHub
parent ec8fad5b02
commit c362ea7fd4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 2 deletions

View file

@ -22,7 +22,7 @@ use super::helpers::{
};
/// ## What it does
/// Checks for parameter-free `@pytest.fixture()` decorators with or without
/// Checks for argument-free `@pytest.fixture()` decorators with or without
/// parentheses, depending on the `flake8-pytest-style.fixture-parentheses`
/// setting.
///
@ -328,6 +328,40 @@ impl AlwaysAutofixableViolation for PytestUselessYieldFixture {
}
}
/// ## What it does
/// Checks for `pytest.mark.usefixtures` decorators applied to `pytest`
/// fixtures.
///
/// ## Why is this bad?
/// The `pytest.mark.usefixtures` decorator has no effect on `pytest` fixtures.
///
/// ## Example
/// ```python
/// @pytest.fixture()
/// def a():
/// pass
///
///
/// @pytest.mark.usefixtures("a")
/// @pytest.fixture()
/// def b(a):
/// pass
/// ```
///
/// Use instead:
/// ```python
/// @pytest.fixture()
/// def a():
/// pass
///
///
/// @pytest.fixture()
/// def b(a):
/// pass
/// ```
///
/// ## References
/// - [`pytest` documentation: `pytest.mark.usefixtures`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-usefixtures)
#[violation]
pub struct PytestErroneousUseFixturesOnFixture;

View file

@ -10,7 +10,7 @@ use crate::registry::{AsRule, Rule};
use super::helpers::get_mark_decorators;
/// ## What it does
/// Checks for parameter-free `@pytest.mark.<marker>()` decorators with or
/// Checks for argument-free `@pytest.mark.<marker>()` decorators with or
/// without parentheses, depending on the `flake8-pytest-style.mark-parentheses`
/// setting.
///
@ -66,6 +66,30 @@ impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle {
}
}
/// ## What it does
/// Checks for `@pytest.mark.usefixtures()` decorators that aren't passed any
/// arguments.
///
/// ## Why is this bad?
/// A `@pytest.mark.usefixtures()` decorator that isn't passed any arguments is
/// useless and should be removed.
///
/// ## Example
/// ```python
/// @pytest.mark.usefixtures()
/// def test_something():
/// ...
/// ```
///
/// Use instead:
/// ```python
/// def test_something():
/// ...
/// ```
///
/// ## References
/// - [`pytest` documentation: `pytest.mark.usefixtures`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-usefixtures)
#[violation]
pub struct PytestUseFixturesWithoutParameters;