{"record":{"id":"1686e761e7e55bae","repo":"astral-sh/ruff","slug":"missing-argument-text","errorCode":null,"errorMessage":"Missing argument `text`","messagePattern":"Missing argument `text`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs","lineNumber":422,"sourceCode":"                    Ok(assert(&isinstance, msg))\n                } else {\n                    let node = ast::ExprUnaryOp {\n                        op: UnaryOp::Not,\n                        operand: Box::new(isinstance),\n                        range: TextRange::default(),\n                        node_index: ruff_python_ast::AtomicNodeIndex::NONE,\n                    };\n                    let expr = node.into();\n                    Ok(assert(&expr, msg))\n                }\n            }\n            UnittestAssert::Regex\n            | UnittestAssert::RegexpMatches\n            | UnittestAssert::NotRegex\n            | UnittestAssert::NotRegexpMatches => {\n                let text = args\n                    .get(\"text\")\n                    .ok_or_else(|| anyhow!(\"Missing argument `text`\"))?;\n                let regex = args\n                    .get(\"regex\")\n                    .ok_or_else(|| anyhow!(\"Missing argument `regex`\"))?;\n                let msg = args.get(\"msg\").copied();\n                let node = ast::ExprName {\n                    id: Name::new_static(\"re\"),\n                    ctx: ExprContext::Load,\n                    range: TextRange::default(),\n                    node_index: ruff_python_ast::AtomicNodeIndex::NONE,\n                };\n                let node1 = ast::ExprAttribute {\n                    value: Box::new(node.into()),\n                    attr: Identifier::new(\"search\".to_string(), TextRange::default()),\n                    ctx: ExprContext::Load,\n                    range: TextRange::default(),\n                    node_index: ruff_python_ast::AtomicNodeIndex::NONE,\n                };\n                let node2 = ast::ExprCall {","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/astral-sh/ruff/blob/15f3fe6b15a5f00172f34b0f542f8ea277f5a586/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs#L404-L440","documentation":"`generate_assert` rewrites `assertRegex`/`assertRegexpMatches`/`assertNotRegex`/`assertNotRegexpMatches` into `re.search(regex, text)` wrapped in an `assert`. The `text` (first) argument is mandatory; if the argument map has no `\"text\"` entry, the rewrite aborts with this error.","triggerScenarios":"`UnittestAssert::Regex | RegexpMatches | NotRegex | NotRegexpMatches.generate_assert` where the source call has no first positional argument and no `text=` keyword — e.g. `self.assertRegex()` or a call passing only `regex=`/`msg=`.","commonSituations":"Incomplete regex assertions bulk-fixed via `ruff --fix` (PT009); legacy `assertRegexpMatches` aliases whose argument lists were edited down; dynamic methods matching the names without unittest's signature.","solutions":["Fix the test call to pass the text first: `self.assertRegex(output, r'\\d+')`.","Use `# noqa: PT009` or per-file ignores when the call should not be rewritten.","If developing Ruff, confirm `arg_spec = ['text', 'regex', 'msg']` and positional insertion of `text` in `args_map`.","Run `ruff check --no-fix` to see the diagnostic and pinpoint the call."],"exampleFix":"// before\nself.assertRegex(pattern=r'abc')\n// after\nself.assertRegex(output, r'abc')","handlingStrategy":"validation","validationCode":"def valid_regex_assert(call_args, call_kwargs):\n    return len(call_args) >= 1 or 'text' in call_kwargs","typeGuard":"def has_text(args: tuple, kwargs: dict) -> bool:\n    return len(args) >= 1 or 'text' in kwargs","tryCatchPattern":null,"preventionTips":["Call assertRegex(text, pattern) with text as the first argument.","Migrate legacy assertRegexpMatches calls carefully, keeping both arguments.","Run ruff check before autofix in CI to catch incomplete regex asserts.","Do not strip arguments when converting between assert* regex aliases."],"tags":["linter","rust","pytest-style","argument-missing","regex"],"backgroundTag":"missing-required-argument","analyzedSha":"15f3fe6b15a5f00172f34b0f542f8ea277f5a586","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}