{"record":{"id":"f0563e0f08a4ade5","repo":"astral-sh/ruff","slug":"expected-assert-statement-to-be-a-composite-condit","errorCode":null,"errorMessage":"Expected assert statement to be a composite condition","messagePattern":"Expected assert statement to be a composite condition","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs","lineNumber":792,"sourceCode":"    };\n\n    // Extract the individual conditions.\n    let mut conditions: Vec<Expression> = Vec::with_capacity(2);\n    match &assert_statement.test {\n        Expression::UnaryOperation(op) => {\n            if matches!(op.operator, libcst_native::UnaryOp::Not { .. }) {\n                if let Expression::BooleanOperation(boolean_operation) = &*op.expression {\n                    if matches!(boolean_operation.operator, BooleanOp::Or { .. }) {\n                        conditions.push(negate(&parenthesize(\n                            &boolean_operation.left,\n                            &op.expression,\n                        )));\n                        conditions.push(negate(&parenthesize(\n                            &boolean_operation.right,\n                            &op.expression,\n                        )));\n                    } else {\n                        bail!(\"Expected assert statement to be a composite condition\");\n                    }\n                } else {\n                    bail!(\"Expected assert statement to be a composite condition\");\n                }\n            }\n        }\n        Expression::BooleanOperation(op) => {\n            if matches!(op.operator, BooleanOp::And { .. }) {\n                conditions.push(parenthesize(&op.left, &assert_statement.test));\n                conditions.push(parenthesize(&op.right, &assert_statement.test));\n            } else {\n                bail!(\"Expected assert statement to be a composite condition\");\n            }\n        }\n        _ => bail!(\"Expected assert statement to be a composite condition\"),\n    }\n\n    // For each condition, create an `assert condition` statement.","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs#L774-L810","documentation":"An anyhow bail! in the PT018 composite-condition fixer: the assert statement's test does not decompose into the composite (and/or with not) condition shapes the fixer knows how to split into individual conditions. The fix is aborted rather than producing a wrong rewrite.","triggerScenarios":"Thrown at crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs:792 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Extend the condition extraction to cover the encountered expression shape","Restrict the rule to condition shapes the fixer can decompose"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}