我在python3中有这段代码
context.execute_steps(
"""
Given user is on the landing page
When he clicks the LOGIN button
And he provides the correct credential
And clicks the login button
Then he should be get into the main page
""".format(
button_color="red"
)
)
...
[当我运行“ pre-commit run --all-files”以便在git / Master中检查代码时,出现这种错误:
..\testcase.py error: Not all arguments converted during string formatting
,抱怨这段代码不好。我该怎么做才能通过?
谢谢,
杰克
感谢大家的反馈。
1)我正在尝试编写一个Python案例,要求用户从浏览器中单击选项卡。可能有两种情况:A)用户已经登录,他可以直接单击。 B)他可能需要先登录自己,然后单击该选项卡。如果是后一种情况,我想通过使用此context.execute_steps()调用来调用在其他地方定义的登录代码。
2)这是我的代码。
@given("make sure the user log-in")
def step_given_user_has_logged_in(context):
if context.holder.logged_in is True:
context.logger.info("user already login.")
return
else:
context.logger.info("user need to do login first.")
context.execute_steps(
"""
Given user is on the landing page
When he clicks the LOGIN button
And he provides the correct credential
And clicks the login button
Then he should be get into the extender main page
""".format(button="red")
)
context.holder.logged_in = True
return
此context.execute_steps()可以从以下链接中引用:https://behave.readthedocs.io/en/latest/api.html,以某种方式,当我执行预提交时,它会给我这样的消息:
testcase.py:29: error: Not all arguments converted during string formatting
我现在才意识到,我可以通过这种方式来解决:
context.execute_steps(
"""
Given user is on the landing page
When he clicks the LOGIN button
And he provides the correct credential
And clicks the login button
Then he should be get into the extender main page
""")
它仍然对我有用,可用于用户登录,它绕过了预提交检查失败。
在我的环境中,我正在使用python 3.7,预提交版本1.2.0,并且它在Ubuntu 16.0.4上运行