{"id":"f389a931ee3d64df","repo":"pytest-dev/pytest","slug":"escaping-with-not-supported-in-marker-expressi","errorCode":null,"errorMessage":"escaping with \"\\\" not supported in marker expression","messagePattern":"escaping with \"\\\\\" not supported in marker expression","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/_pytest/mark/expression.py","lineNumber":106,"sourceCode":"            elif input[pos] == \")\":\n                yield Token(TokenType.RPAREN, \")\", pos)\n                pos += 1\n            elif input[pos] == \"=\":\n                yield Token(TokenType.EQUAL, \"=\", pos)\n                pos += 1\n            elif input[pos] == \",\":\n                yield Token(TokenType.COMMA, \",\", pos)\n                pos += 1\n            elif (quote_char := input[pos]) in (\"'\", '\"'):\n                end_quote_pos = input.find(quote_char, pos + 1)\n                if end_quote_pos == -1:\n                    raise SyntaxError(\n                        f'closing quote \"{quote_char}\" is missing',\n                        (FILE_NAME, 1, pos + 1, input),\n                    )\n                value = input[pos : end_quote_pos + 1]\n                if (backslash_pos := value.find(\"\\\\\")) != -1:\n                    raise SyntaxError(\n                        r'escaping with \"\\\" not supported in marker expression',\n                        (FILE_NAME, 1, pos + backslash_pos + 1, input),\n                    )\n                yield Token(TokenType.STRING, value, pos)\n                pos += len(value)\n            else:\n                match = re.match(r\"(:?\\w|:|\\+|-|\\.|\\[|\\]|\\\\|/)+\", input[pos:])\n                if match:\n                    value = match.group(0)\n                    if value == \"or\":\n                        yield Token(TokenType.OR, value, pos)\n                    elif value == \"and\":\n                        yield Token(TokenType.AND, value, pos)\n                    elif value == \"not\":\n                        yield Token(TokenType.NOT, value, pos)\n                    else:\n                        yield Token(TokenType.IDENT, value, pos)\n                    pos += len(value)","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/mark/expression.py#L88-L124","documentation":"The match-expression scanner explicitly forbids backslash escapes inside string literals. If a `\\` appears anywhere between the opening and closing quote, this SyntaxError is raised at the backslash's column. Marker kwarg values are taken literally; no escape processing is performed.","triggerScenarios":"Writing `-m 'foo(path=\"a\\b\")'` or otherwise trying to embed a backslash (Windows path, regex) inside a marker kwarg string.","commonSituations":"Pasting Windows file paths or regex patterns into a marker kwarg value; assuming Python string-escape semantics apply.","solutions":["Remove backslashes from the kwarg value, or replace them with forward slashes / a different separator.","If a literal backslash is genuinely required, move that logic out of the marker expression (use a real fixture/parametrize id instead).","Use raw values that contain no `\\`."],"exampleFix":"# before\npytest -m 'filter(path=\"C:\\\\tmp\")'\n# after\npytest -m 'filter(path=\"C:/tmp\")'","handlingStrategy":"validation","validationCode":"def has_no_backslash_in_strings(expr: str) -> bool:\n    # marker kwarg string values cannot contain a backslash\n    return chr(92) not in expr","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid Windows-style backslash paths in marker kwarg values.","If a separator is needed, use `/` or `-`."],"tags":["pytest","marker-expression","scanner","escaping"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}