diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index f05d4cbcfb5..8b61eceb2ee 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -789,9 +789,6 @@ def visit_Assert(self, assert_): self.variables = [] # type: List[str] self.variable_counter = itertools.count() - if self.enable_assertion_pass_hook: - self.format_variables = [] # type: List[str] - self.stack = [] # type: List[Dict[str, ast.expr]] self.expl_stmts = [] # type: List[ast.stmt] self.push_format_context() @@ -808,6 +805,7 @@ def visit_Assert(self, assert_): negation = ast.UnaryOp(ast.Not(), top_condition) if self.enable_assertion_pass_hook: # Experimental pytest_assertion_pass hook + self.format_variables = [] # type: List[str] msg = self.pop_format_context(ast.Str(explanation)) # Failed