From fbfb4ebf58f2203b06dba0d67207d8508fa20efa Mon Sep 17 00:00:00 2001 From: Max Berkowitz Date: Fri, 26 Apr 2024 00:34:48 -0400 Subject: [PATCH] Make mark verification occur in expression compilation --- src/_pytest/mark/expression.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/_pytest/mark/expression.py b/src/_pytest/mark/expression.py index 93e784911..d9a241834 100644 --- a/src/_pytest/mark/expression.py +++ b/src/_pytest/mark/expression.py @@ -200,12 +200,19 @@ class Expression: self.code = code @classmethod - def compile(self, input: str) -> "Expression": + def compile(self, input: str, mark: bool = False) -> "Expression": """Compile a match expression. :param input: The input expression - one line. """ astexpr = expression(Scanner(input)) + + if mark: + for node in ast.walk(astexpr): + #if the node is an identifier, i.e. a mark name + if isinstance(node, ast.Name): + MARK_GEN.verify_mark(node.id[len(IDENT_PREFIX):]) + code: types.CodeType = compile( astexpr, filename="",