{"record":{"id":"bfafaf863c17acf9","repo":"pytest-dev/pytest","slug":"closing-quote-quote-char-is-missing","errorCode":null,"errorMessage":"closing quote \"{quote_char}\" is missing","messagePattern":"closing quote \"(.+?)\" is missing","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/_pytest/mark/expression.py","lineNumber":100,"sourceCode":"        while pos < len(input):\n            if input[pos] in (\" \", \"\\t\"):\n                pos += 1\n            elif input[pos] == \"(\":\n                yield Token(TokenType.LPAREN, \"(\", pos)\n                pos += 1\n            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\":","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/mark/expression.py#L82-L118","documentation":"A SyntaxError raised by the marker-expression tokenizer when it finds an opening single or double quote with no matching close quote before end of input. It carries the FILE_NAME, line 1, the 1-based column of the opening quote, and the raw input so pytest can render a caret. String literals are used for kwarg values inside marker expressions like `@pytest.mark.foo(bar=\"x\")` parsed via -m.","triggerScenarios":"Passing `-m \"my_mark(name='value)\"` (missing close quote), `-m \"my_mark(\\\"x)\"`, or any marker expression whose quoted value is truncated. The tokenizer enters the quote branch because input[pos] is ' or \\\" and input.find never returns a second quote.","commonSituations":"Shell escaping mistakes (the shell consumes the closing quote), generating marker expressions from untrusted strings without escaping, or hand-editing a marker filter and dropping the trailing quote.","solutions":["Inspect the column reported in the error; it points at the unmatched opening quote.","Add the matching close quote of the same character.","Quote the entire -m argument with single quotes in the shell and use double quotes inside, or vice versa.","Avoid backslashes in marker values (see error 122); they are unsupported."],"exampleFix":"# before\npytest -m \"my_mark(name='value)\"\n# after\npytest -m \"my_mark(name='value')\"","handlingStrategy":"validation","validationCode":"def has_balanced_quotes(s: str) -> bool:\n    for q in (\"'\", '\"'):\n        if s.count(q) % 2 != 0:\n            return False\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    Expression.compile(expr)\nexcept SyntaxError as e:\n    if 'closing quote' in e.msg:\n        # prompt user to fix quoting\n        ...","preventionTips":["Always close quotes in marker values.","Use the opposite quote style at the shell level to protect inner quotes.","Avoid embedding complex strings in marker expressions."],"tags":["pytest","marker-expression","tokenizer","syntax-error","quoting"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}