那是合乎逻辑的:**凭证意味着你将提供它的命名参数.但是你没有提供字典的名称.
这里有两种可能性:
>您使用凭证作为单个参数,并将其传递给字典,如:
def submit_new_account_form(self, credentials):
# ...
pass
loginpage.submit_new_account_form({'first_name': 'Test', 'last_name': 'Test', 'phone_or_email': temp_email, 'newpass': '1q2w3e4r5t', 'sex': 'male'})
>通过在前面放两个星号,将字典作为命名参数传递:
def submit_new_account_form(self, **credentials):
# ...
pass
loginpage.submit_new_account_form(**{'first_name': 'Test', 'last_name': 'Test', 'phone_or_email': temp_email, 'newpass': '1q2w3e4r5t', 'sex': 'male'})
第二种方法等于传递命名参数,如:
loginpage.submit_new_account_form(first_name='Test', last_name='Test', phone_or_email=temp_email, newpass='1q2w3e4r5t', sex='male')
我认为最后一种方法是更清晰的语法.此外,它允许您轻松修改submit_new_account_form函数签名的签名以立即捕获某些参数,而不是将它们包装到字典中.