考虑一个行为场景:
When some magic number is generated
Then the number should be greater than 5
所以我有一个@when函数产生(比方说)一个随机数,我需要在@then条件测试中出现这个数字。
如何将一步结果传递给另一步?
答案 0 :(得分:10)
您可以在传递给步骤的上下文对象上设置数据。来自the documentation:
@given('I request a new widget for an account via SOAP')
def step_impl(context):
client = Client("http://127.0.0.1:8000/soap/")
context.response = client.Allocate(customer_first='Firstname',
customer_last='Lastname', colour='red')
@then('I should receive an OK SOAP response')
def step_impl(context):
eq_(context.response['ok'], 1)
您还可以在测试运行中,每个步骤之前和之后,功能,方案,标记等进行modify the context at various other points。