mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Add PT013 and PT015 docs (#6303)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> #2646 ## Test Plan <!-- How was it tested? -->
This commit is contained in:
parent
9f3567dea6
commit
b6f0316d55
2 changed files with 40 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue