2012-08-27 3 views
3

일반적으로 각 양상추 테스트 단계에서 1 개의 매개 변수를 사용하는 여러 인수를 전달하면 한 번에 여러 인수를 전달할 수있는 방법이 있습니까? 무엇 당신이 그 일을 방지양상추 테스트 단계

@step('I have the number (\d+) and character (\w+)') 
def have_the_number(step, number, character): 
    world.number = int(number) 
    world.character = str(character) 

답변

2

코드가 완벽하게 유효합니다. 당신의 위치 인자 (예 : *args)와 이름이 같은 것 (예 : **kwargs)을 모두 사용할 수 있습니다.

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 :

당신이 math.feature 다음이 고려

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 

은 뺄셈의 예를 자세히보세요, 당신이 오히려 이름으로 캡처 된 변수를 참조하는 방법을 보여줍니다 다음 위치로.

1

: 같은

,이있을 수 있습니까? 예제와 같이 한 번에 여러 개의 인수를 사용할 수 있습니다.

단계 이름이 정규식 패턴으로 구문 분석 된 것 같아요. 일치하는 그룹은 매개 변수로 단계 핸들러에서 전달됩니다.

+0

예를 들어 이런 식으로 사용하지는 않으므로이 사용법과 관련된 설명서 항목이 있습니까? 어쨌든 나는 검증 할 것이다. – zinking

+0

나는이 모든 것을 내 프로젝트에서 사용한다. 당신이 직면 한 문제는 그것이 효과가 없을 것이라고 믿게합니까? –

+0

아무 문제 없어, 내 프로젝트에서 아무도 이런 식으로 사용하지 않습니다. 확인해주세요. – zinking

관련 문제