あなたのコードは完全に有効です。位置引数(*args
例のように など)と名前付き引数( など)の両方を使用できます**kwargs
。
あなたが次のものを持っていると考えてくださいmath.feature
:
Feature: Basic computations
In order to play with Lettuce
As beginners
We will implement addition and subtraction
Scenario: Sum of 0 and 1
Given I have to add the numbers 0 and 1
When I compute its factorial
Then I see the number 1
Scenario: Difference of 3 and 5
Given I have to substract 5 from 3
When I compute their difference
Then I see the number -2
などsteps.py
:
from lettuce import *
@step('I have to add the numbers (\d+) and (\d+)')
def have_to_add(step, number1, number2):
world.number1 = int(number1)
world.number2 = int(number2)
@step('I have to substract (?P<subtrahend>) from (?P<minuend>)')
def have_to_substract(step, minuend, subtrahend):
world.minuend = int(minuend)
world.subtrahend = int(subtrahend)
@step('I compute their difference')
def compute_difference(step):
world.number = world.minuend - world.subtrahend
@step('I compute their sum')
def compute_sum(step):
world.number = world.number1 + world.number2
@step('I see the number (\d+)')
def check_number(step, expected):
expected = int(expected)
assert world.number == expected, "Got %d" % world.number
減算の例を詳しく見てみましょう。キャプチャされた変数を位置ではなく名前で参照する方法を示しています。