Как изобразить «А» в Python, вести себя как шаг определения - PullRequest
0 голосов
/ 08 ноября 2018

Например, у меня есть следующий сценарий в файле объектов

Scenario: A Scenario
    Given a precondition
    When step 1
    And step 2
    Then step 3

В Ruby я могу написать пошаговое определение для приведенного выше сценария следующим образом:

Given("a precondition") do

end

When("step 1") do

end

And("step 2") do

end

Then("step 3") do

end

Я должен реализовать это с помощью Python Behave, и я запутался в аннотации и реализации в пошаговом определении для этого, я не нашел @and в приведенных мною примерах.

@given("a precondition")
def given_implementation(context)
    pass

@when("step 1")
def when_implementation(context)
    pass

#which annotation to use for and??
def and_implementation(context)
    pass

@then("step 3")
def then_implementation(context):
    pass

1 Ответ

0 голосов
/ 08 ноября 2018

And просто наследуется от того, чем был предыдущий шаг. Из документов ,

From website

Итак, в вашем случае вы хотели бы изменить шаг реализации следующим образом:

@given("a precondition")
def given_implementation(context)
    pass

@when("step 1")
def when_implementation(context)
    pass

@when("step 2") <--------------------- Changed to this!
def and_implementation(context)
    pass

@then("step 3")
def then_implementation(context):
    pass
...