我有一个行为python测试用例在代码预提交期间失败



我在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"
)
)
...

当我运行一个"预提交运行-所有文件"到,以便在git/Master中进行代码检查时,我会遇到这种故障:

..testcase.py error: Not all arguments converted during string formatting

,抱怨这段代码不好。我能做些什么来度过难关?

谢谢,

Jack

感谢大家的反馈。

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 上运行

最新更新