{"record":{"id":"de9a487940d93909","repo":"pytest-dev/pytest","slug":"unexpected-character-input-pos","errorCode":null,"errorMessage":"unexpected character \"{input[pos]}\"","messagePattern":"unexpected character \"(.+?)\"","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/_pytest/mark/expression.py","lineNumber":126,"sourceCode":"                        (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)\n                else:\n                    raise SyntaxError(\n                        f'unexpected character \"{input[pos]}\"',\n                        (FILE_NAME, 1, pos + 1, input),\n                    )\n        yield Token(TokenType.EOF, \"\", pos)\n\n    @overload\n    def accept(self, type: TokenType, *, reject: Literal[True]) -> Token: ...\n\n    @overload\n    def accept(\n        self, type: TokenType, *, reject: Literal[False] = False\n    ) -> Token | None: ...\n\n    def accept(self, type: TokenType, *, reject: bool = False) -> Token | None:\n        if self.current.type is type:\n            token = self.current\n            if token.type is not TokenType.EOF:\n                self.current = next(self.tokens)","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/mark/expression.py#L108-L144","documentation":"A SyntaxError raised by the marker-expression tokenizer when the current character matches none of the recognized token starts (whitespace, parens, =, comma, quote, or the identifier/number regex). The unexpected character and its 1-based column are reported. It is the catch-all lexical error for anything the grammar cannot start to tokenize.","triggerScenarios":"Expressions containing characters like `@`, `#`, `$`, `%`, `;`, or unicode symbols that are not part of identifier/number/keyword grammar. For example `-m '@smoke'`, `-k 'test_##'`, or `-m 'a;b'`.","commonSituations":"Pasting a Python expression into -m expecting full Python syntax; using decorator-style or comment characters; locale/keyboard producing unexpected symbols.","solutions":["Read the reported character and column; remove or replace it.","Restrict marker expressions to identifiers, `and`, `or`, `not`, parentheses, and (for kwargs) `name=value` literals.","If you need richer filtering, write a conftest hook (pytest_collection_modifyitems) instead of a CLI expression."],"exampleFix":"# before\npytest -m '@smoke'\n# after\npytest -m 'smoke'","handlingStrategy":"validation","validationCode":"import re\nVALID_EXPR_CHARS = re.compile(r\"^[\\w\\s()=,.'\\\"]+$\")\ndef looks_like_marker_expr(s: str) -> bool:\n    return bool(VALID_EXPR_CHARS.match(s))","typeGuard":null,"tryCatchPattern":"try:\n    Expression.compile(expr)\nexcept SyntaxError as e:\n    # surface the unexpected character to the user\n    ...","preventionTips":["Restrict marker expressions to identifier and operator characters.","Do not paste arbitrary Python expressions into -m/-k.","Validate user-supplied filter strings before running pytest."],"tags":["pytest","marker-expression","tokenizer","syntax-error","lexing"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}