Skip to content

Commit 95c4457

Browse files
committed
Add docs
1 parent 992c655 commit 95c4457

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ use super::helpers::is_empty_or_null_string;
2020
/// A `pytest.raises` context manager should only contain a single simple
2121
/// statement that raises the expected exception.
2222
///
23+
/// In [preview], this rule allows `pytest.raises` bodies to contain `for`
24+
/// loops with empty bodies (e.g., `pass` or `...` statements), to test
25+
/// iterator behavior.
26+
///
2327
/// ## Example
2428
/// ```python
2529
/// import pytest
@@ -46,6 +50,8 @@ use super::helpers::is_empty_or_null_string;
4650
///
4751
/// ## References
4852
/// - [`pytest` documentation: `pytest.raises`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-raises)
53+
///
54+
/// [preview]: https://docs.astral.sh/ruff/preview/
4955
#[derive(ViolationMetadata)]
5056
pub(crate) struct PytestRaisesWithMultipleStatements;
5157

@@ -209,8 +215,9 @@ pub(crate) fn complex_raises(
209215

210216
match stmt {
211217
Stmt::With(ast::StmtWith { body, .. }) => is_non_trivial_with_body(body),
212-
// Allow function and class definitions to test decorators
218+
// Allow function and class definitions to test decorators.
213219
Stmt::ClassDef(_) | Stmt::FunctionDef(_) => false,
220+
// Allow empty `for` loops to test iterators.
214221
Stmt::For(ast::StmtFor { body, .. }) if in_preview => match &body[..] {
215222
[Stmt::Pass(_)] => false,
216223
[Stmt::Expr(ast::StmtExpr { value, .. })] => !value.is_ellipsis_literal_expr(),

crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ use super::helpers::is_empty_or_null_string;
2020
/// A `pytest.warns` context manager should only contain a single
2121
/// simple statement that triggers the expected warning.
2222
///
23+
/// In [preview], this rule allows `pytest.warns` bodies to contain `for`
24+
/// loops with empty bodies (e.g., `pass` or `...` statements), to test
25+
/// iterator behavior.
26+
///
2327
/// ## Example
2428
/// ```python
2529
/// import pytest
@@ -38,12 +42,14 @@ use super::helpers::is_empty_or_null_string;
3842
///
3943
/// def test_foo_warns():
4044
/// setup()
41-
/// with pytest.warning(Warning):
45+
/// with pytest.warns(Warning):
4246
/// foo()
4347
/// ```
4448
///
4549
/// ## References
4650
/// - [`pytest` documentation: `pytest.warns`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-warns)
51+
///
52+
/// [preview]: https://docs.astral.sh/ruff/preview/
4753
#[derive(ViolationMetadata)]
4854
pub(crate) struct PytestWarnsWithMultipleStatements;
4955

@@ -204,8 +210,9 @@ pub(crate) fn complex_warns(checker: &mut Checker, stmt: &Stmt, items: &[WithIte
204210

205211
match stmt {
206212
Stmt::With(ast::StmtWith { body, .. }) => is_non_trivial_with_body(body),
207-
// Allow function and class definitions to test decorators
213+
// Allow function and class definitions to test decorators.
208214
Stmt::ClassDef(_) | Stmt::FunctionDef(_) => false,
215+
// Allow empty `for` loops to test iterators.
209216
Stmt::For(ast::StmtFor { body, .. }) if in_preview => match &body[..] {
210217
[Stmt::Pass(_)] => false,
211218
[Stmt::Expr(ast::StmtExpr { value, .. })] => !value.is_ellipsis_literal_expr(),

ruff.schema.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)