From 195422f9c08582c4e9c5cd85ead1e0cec1879c34 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 15 Jul 2015 15:31:35 -0700 Subject: [PATCH] Fix AST rewriting with starred expressions in function calls --- _pytest/assertion/rewrite.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index fae313e30..97263cd69 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -775,10 +775,7 @@ class AssertionRewriter(ast.NodeVisitor): new_kwargs = [] for arg in call.args: res, expl = self.visit(arg) - if type(arg) is ast.Starred: - arg_expls.append("*" + expl) - else: - arg_expls.append(expl) + arg_expls.append(expl) new_args.append(res) for keyword in call.keywords: res, expl = self.visit(keyword.value) @@ -795,6 +792,11 @@ class AssertionRewriter(ast.NodeVisitor): outer_expl = "%s\n{%s = %s\n}" % (res_expl, res_expl, expl) return res, outer_expl + def visit_Starred(self, starred): + # From Python 3.5, a Starred node can appear in a function call + res, expl = self.visit(starred.value) + return starred, '*' + expl + def visit_Call_legacy(self, call): """ visit `ast.Call nodes on 3.4 and below`