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:
Harutaka Kawamura 2023-08-03 23:51:52 +09:00 committed by GitHub
parent 9f3567dea6
commit b6f0316d55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View file

@ -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;

View file

@ -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;