考虑一个行为场景:
When some magic number is generated
Then the number should be greater than 5
所以我有一个@when 函数,它产生(比如说)一个随机数,我需要该数字出现在@then 条件测试中。
如何将一个步骤的结果传递给另一个?
考虑一个行为场景:
When some magic number is generated
Then the number should be greater than 5
所以我有一个@when 函数,它产生(比如说)一个随机数,我需要该数字出现在@then 条件测试中。
如何将一个步骤的结果传递给另一个?
您可以在传递给步骤的上下文对象上设置数据。从文档中:
@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)
您还可以在测试运行的各个其他点、每个步骤、功能、场景、标签等之前和之后修改上下文。