{"record":{"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":"validation","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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/mark/__init__.py#L190-L226","documentation":"In the keyword expression matcher (mark/__init__.py:208), __call__ rejects any keyword arguments because '-k' keyword expressions only support names and boolean operators, not function-call syntax like 'name(value)'. If kwargs are passed (e.g. the parsed expression contained a call), pytest raises UsageError('Keyword expressions do not support call parameters.') rather than silently misbehaving.","triggerScenarios":"Writing 'pytest -k \"test_name(smoke)\"' or any '-k' expression using parentheses with arguments; a programmatically constructed MarkMatcher invoked with kwargs; a parsed expression tree that synthesizes a call node.","commonSituations":"Confusing '-k' (keyword filter) with '-m' (mark filter) syntax; attempting to pass parameters via the keyword expression; copy-pasting function-call syntax into the keyword argument.","solutions":["Use only names and boolean operators in -k: 'pytest -k \"test_name and not slow\"'.","Use marks (@pytest.mark.smoke) and '-m smoke' if you need categorical filtering.","Remove any '(...)' call syntax from the -k expression."],"exampleFix":"// before\npytest -k \"login(smoke)\"\n// after\npytest -k \"login and smoke\"","handlingStrategy":"validation","validationCode":"import re\ndef validate_keyword_expr(expr: str) -> str:\n    if re.search(r'\\w+\\s*\\([^)]*\\)', expr):\n        raise ValueError(\"'-k' does not allow call syntax 'name(...)'; use names and and/or/not\")\n    return expr","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict '-k' to names plus and/or/not operators.","Use marks and '-m' for categorical/parameterized filtering.","Validate user-supplied '-k' strings before invoking pytest."],"tags":["pytest","keyword","selection","cli","mark"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}