Simplify `flake8_pytest_style::rules::fail_call` implementation (#14556)

This commit is contained in:
Harutaka Kawamura 2024-11-23 23:14:28 +09:00 committed by GitHub
parent 07d13c6b4a
commit 1f303a5eb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 10 deletions

View File

@ -59,18 +59,12 @@ pub(crate) fn fail_call(checker: &mut Checker, call: &ast::ExprCall) {
if is_pytest_fail(&call.func, checker.semantic()) {
// Allow either `pytest.fail(reason="...")` (introduced in pytest 7.0) or
// `pytest.fail(msg="...")` (deprecated in pytest 7.0)
let msg = call
if call
.arguments
.find_argument("reason", 0)
.or_else(|| call.arguments.find_argument("msg", 0));
if let Some(msg) = msg {
if is_empty_or_null_string(msg) {
checker
.diagnostics
.push(Diagnostic::new(PytestFailWithoutMessage, call.func.range()));
}
} else {
.or_else(|| call.arguments.find_argument("msg", 0))
.map_or(true, is_empty_or_null_string)
{
checker
.diagnostics
.push(Diagnostic::new(PytestFailWithoutMessage, call.func.range()));