{"id":"3384ffb601b112eb","repo":"pytest-dev/pytest","slug":"keyword-expressions-do-not-support-call-parameters","errorCode":null,"errorMessage":"Keyword expressions do not support call parameters.","messagePattern":"Keyword expressions do not support call parameters\\.","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/mark/__init__.py","lineNumber":208,"sourceCode":"                continue\n            mapped_names.add(node.name)\n\n        # Add the names added as extra keywords to current or parent items.\n        mapped_names.update(item.listextrakeywords())\n\n        # Add the names attached to the current function through direct assignment.\n        function_obj = getattr(item, \"function\", None)\n        if function_obj:\n            mapped_names.update(function_obj.__dict__)\n\n        # Add the markers to the keywords as we no longer handle them correctly.\n        mapped_names.update(mark.name for mark in item.iter_markers())\n\n        return cls(mapped_names)\n\n    def __call__(self, subname: str, /, **kwargs: str | int | bool | None) -> bool:\n        if kwargs:\n            raise UsageError(\"Keyword expressions do not support call parameters.\")\n        subname = subname.lower()\n        return any(subname in name.lower() for name in self._names)\n\n\ndef deselect_by_keyword(items: list[Item], config: Config) -> None:\n    keywordexpr = config.option.keyword.lstrip()\n    if not keywordexpr:\n        return\n\n    expr = _parse_expression(keywordexpr, \"Wrong expression passed to '-k'\")\n\n    remaining = []\n    deselected = []\n    for colitem in items:\n        if not expr.evaluate(KeywordMatcher.from_item(colitem)):\n            deselected.append(colitem)\n        else:\n            remaining.append(colitem)","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/mark/__init__.py#L190-L226","documentation":"Raised by `KeywordMatcher.__call__` when a `-k` keyword expression invokes a name with call parameters (parentheses with kwargs). pytest's `-k` expressions match substrings of test/keyword names only; they are not function calls, so `name(arg=value)` syntax is rejected with UsageError.","triggerScenarios":"Running `pytest -k \"test_foo(bar)\"` or `-k \"login(user=admin)\"`. The expression parser yields a matcher call with kwargs, which KeywordMatcher.__call__ rejects.","commonSituations":"Confusing `-k` keyword matching with marker/parametrize syntax. Trying to filter by parametrize ids via `-k` using call notation. Copying parametrize ids that contain parentheses into a `-k` expression.","solutions":["Use plain substring tokens in `-k`: `pytest -k \"test_foo and login\"`.","To filter by parametrize ids, match the id substring: `pytest -k \"user_admin\"` (without parens).","Use `-m` with markers for structured filtering instead of `-k`."],"exampleFix":"// before\n$ pytest -k \"login(user=admin)\"\n// after\n$ pytest -k \"login and user_admin\"","handlingStrategy":"validation","validationCode":"def validate_keyword_expr(expr: str):\n    import re\n    if re.search(r\"\\w+\\s*\\([^)]*\\)\", expr):\n        raise ValueError(\"Keyword expressions do not support call parameters\")","typeGuard":"def is_plain_keyword_expr(expr: str) -> bool:\n    import re\n    return not re.search(r\"\\w+\\s*\\([^)]*\\)\", expr)","tryCatchPattern":null,"preventionTips":["Use substring tokens combined with and/or/not in -k expressions.","Use -m markers for structured filtering.","Match parametrize ids as substrings without parentheses."],"tags":["pytest","keyword-filter","cli","markers","usageerror"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}