diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs index 552f902078..dd60425922 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs @@ -112,6 +112,29 @@ impl Violation for PytestAssertInExcept { } } +/// ## What it does +/// Checks for `assert` statements whose test expression is a falsy value. +/// +/// ## Why is this bad? +/// `pytest.fail` conveys the intent more clearly than `assert falsy_value`. +/// +/// ## Example +/// ```python +/// def test_foo(): +/// if some_condition: +/// assert False, "some_condition was True" +/// ``` +/// +/// Use instead: +/// ```python +/// def test_foo(): +/// if some_condition: +/// pytest.fail("some_condition was True") +/// ... +/// ``` +/// +/// References +/// - [`pytest` documentation: `pytest.fail`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fail) #[violation] pub struct PytestAssertAlwaysFalse; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs index 394af4ac30..3d689ce765 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs @@ -3,6 +3,23 @@ use ruff_python_ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; +/// ## What it does +/// Checks for incorrect import of pytest. +/// +/// ## Why is this bad? +/// `pytest` should be imported as `import pytest` and its members should be accessed in the form of +/// `pytest.xxx.yyy` for consistency and to make it easier for linting tools to analyze the code. +/// +/// ## Example +/// ```python +/// import pytest as pt +/// from pytest import fixture +/// ``` +/// +/// Use instead: +/// ```python +/// import pytest +/// ``` #[violation] pub struct PytestIncorrectPytestImport;