mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
[flake8-pytest-style
] Tweak documentation and message (#15465)
This commit is contained in:
parent
369cbb5424
commit
9dfc61bf09
3 changed files with 12 additions and 13 deletions
|
@ -16,8 +16,9 @@ use super::helpers::is_empty_or_null_string;
|
||||||
/// ## Why is this bad?
|
/// ## Why is this bad?
|
||||||
/// When a `pytest.raises` is used as a context manager and contains multiple
|
/// When a `pytest.raises` is used as a context manager and contains multiple
|
||||||
/// statements, it can lead to the test passing when it actually should fail.
|
/// statements, it can lead to the test passing when it actually should fail.
|
||||||
/// To avoid this, a `pytest.raises` context manager should only contain
|
///
|
||||||
/// a single simple statement that raises the expected exception.
|
/// A `pytest.raises` context manager should only contain a single simple
|
||||||
|
/// statement that raises the expected exception.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```python
|
/// ```python
|
||||||
|
@ -147,7 +148,7 @@ pub(crate) struct PytestRaisesWithoutException;
|
||||||
impl Violation for PytestRaisesWithoutException {
|
impl Violation for PytestRaisesWithoutException {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
"set the expected exception in `pytest.raises()`".to_string()
|
"Set the expected exception in `pytest.raises()`".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,10 @@ use super::helpers::is_empty_or_null_string;
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def test_foo():
|
/// def test_foo_warns():
|
||||||
/// with pytest.warns(MyWarning):
|
/// with pytest.warns(Warning):
|
||||||
/// setup()
|
/// setup() # False negative if setup triggers a warning but foo does not.
|
||||||
/// func_to_test() # not executed if `setup()` triggers `MyWarning`
|
/// foo()
|
||||||
/// assert foo() # not executed
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
@ -37,11 +36,10 @@ use super::helpers::is_empty_or_null_string;
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def test_foo():
|
/// def test_foo_warns():
|
||||||
/// setup()
|
/// setup()
|
||||||
/// with pytest.warning(MyWarning):
|
/// with pytest.warning(Warning):
|
||||||
/// func_to_test()
|
/// foo()
|
||||||
/// assert foo()
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
|
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
|
||||||
snapshot_kind: text
|
snapshot_kind: text
|
||||||
---
|
---
|
||||||
PT010.py:5:10: PT010 set the expected exception in `pytest.raises()`
|
PT010.py:5:10: PT010 Set the expected exception in `pytest.raises()`
|
||||||
|
|
|
|
||||||
4 | def test_ok():
|
4 | def test_ok():
|
||||||
5 | with pytest.raises():
|
5 | with pytest.raises():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue