This commit is contained in:
mahiro 2025-12-16 16:37:01 -05:00 committed by GitHub
commit 05acfa0a1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -9,3 +9,15 @@ def test_ok():
def test_error(): def test_error():
with pytest.raises(UnicodeError): with pytest.raises(UnicodeError):
pass pass
def test_match_only():
with pytest.raises(match="some error message"):
pass
def test_check_only():
with pytest.raises(check=lambda e: True):
pass
def test_match_and_check():
with pytest.raises(match="some error message", check=lambda e: True):
pass

View File

@ -126,6 +126,9 @@ impl Violation for PytestRaisesTooBroad {
/// `pytest.raises` expects to receive an expected exception as its first /// `pytest.raises` expects to receive an expected exception as its first
/// argument. If omitted, the `pytest.raises` call will fail at runtime. /// argument. If omitted, the `pytest.raises` call will fail at runtime.
/// ///
/// Note: As of pytest 8.4.0, calls with only `match` or `check` keyword
/// arguments (without an exception class) are also valid.
///
/// ## Example /// ## Example
/// ```python /// ```python
/// import pytest /// import pytest
@ -181,6 +184,8 @@ pub(crate) fn raises_call(checker: &Checker, call: &ast::ExprCall) {
.arguments .arguments
.find_argument("expected_exception", 0) .find_argument("expected_exception", 0)
.is_none() .is_none()
&& call.arguments.find_keyword("match").is_none()
&& call.arguments.find_keyword("check").is_none()
{ {
checker.report_diagnostic(PytestRaisesWithoutException, call.func.range()); checker.report_diagnostic(PytestRaisesWithoutException, call.func.range());
} }