Python 有没有一种简单的方法可以将一个步骤定义为既给定又给定

Python 有没有一种简单的方法可以将一个步骤定义为既给定又给定,python,python-behave,Python,Python Behave,我正在构建一个Py-Behave测试框架,并且有许多场景,在这些场景中,以前的步骤变成了给定步骤 例如在一个场景中 Given a user has is on the logon page When they login with credentials <user> Then the user logs in 有没有一种方法可以避免把所有这些步骤都写两遍,但能够定义什么时候是赠品 您可以使用behave中提供的@step decorator 情景一 Given a user

我正在构建一个Py-Behave测试框架,并且有许多场景,在这些场景中,以前的步骤变成了给定步骤

例如在一个场景中

Given a user has is on the logon page 
When they login with credentials <user>
Then the user logs in 

有没有一种方法可以避免把所有这些步骤都写两遍,但能够定义什么时候是赠品

您可以使用behave中提供的@step decorator

情景一

Given a user has is on the logon page 
When they login with credentials <user>
Then the user logs in

参考:

这仍然意味着我正在步骤文件中重复编写代码。另一种方法是,在上面给出的答案之前,我将在另一个步骤中调用该步骤。不,您不必再次编写步骤,只需使用@step decorator编写一个函数,它将完成登录部分,您可以使用它,谢谢您,我误解了那里的描述,这是处理这个问题的另一个很好的方法,在我的例子中,实现上述方法要容易得多。
 @given('they login with credentials {user}')
 def step_impl(context):
    Do login code

 @when('they login with credentials {user}')
 def step_impl(context):
    Do login code
Given a user has is on the logon page 
When they login with credentials <user>
Then the user logs in
Given a user is on the logon page
And they login with credentials <user>
@step('they login with credentials {user}')
 def step_impl(context):
    Do login code