2017-10-25 18 views
0

私の機能を実行する前に、あるステップを実行したい。このステップでは、引数として変数が使用されます。私はcontext.execute_stepsで渡すことができません。python-behaveでcontext.execute_stepsに可変引数を渡す方法

ただし、これは機能しません。変数が引用符で囲まれていないので、引数の解析にエラーが発生します。私は振る舞いのドキュメントでそのような例は見ません。どんな助けでも本当に感謝しています。

答えて

1

何かが起こっている可能性があります。私がhereを見つけたのは、python 3を使用している場合、u'''の前に含めて、ユニコードにする必要があるということです。私はちょっと立ち上がって、(ステップの名前だけでなく)実行ステップコマンドの一部として、またはその後に含める必要がありますが、あなたの例はそれを実行しているようです。私はあなたが変数を渡している方法によって混乱していますが、execute_stepsを使ってPython 2で動作する方法を教えてください。& 3 with 1.2.5。

@step('I set the Number to "{number:d}" exactly') 
def step_impl(context, number): 
    context.number = 10 
    context.number = number 

@step('I call another step') 
def step_impl(context): 
    context.execute_steps(u'''when I set the Number to "5" exactly''') 
    print(context.number) 
    assert context.number == 10, 'This will fail' 

次に呼び出す:ときI set the Number to "5" exactly

Given I call another step 
When some not mentioned step 
Then some other not mentioned step 

はときI call another stepの一部として実行されます。

私はあなたが実行しようとしている他のステップに慣れていないんだけど、あなたのようなもので、前の手順を定義した場合ので、あなたの正確な例えば言ってハード

@step('execute api "{method}" "{version}"') 
def step_impl(context, method, version): 
    # do stuff with passed in method and version variables 

次のことができるようにすべきです別のステップでそう使いましょう。

@step('I call another step') 
def step_impl(context): 
    context.execute_steps(u'''When execute api "get" "version1"''') 

問題がステップ間で情報を渡すだけの場合は、あなたは文脈を使ってそれを渡すことができます。

@step('I do the first function') 
def step_impl(context): 
    context.call1 = "version" 
    context.call1_method = "get" 

@step('I call another step') 
def step_impl(context): 
    print(%s and %s are available in this function % (context.call1, context.call1_method) 

そして行に

When I do the first function 
    And I call another step 
    ... 
+0

'@stepを( '私は別のステップを呼び出す') はDEF(コンテキスト)step_impl手順を呼び出す: context.execute_steps(実行するU ' '' はapi "get" "version1" '' ') ' これは私が欲しかったものです。私はこの構文を得るのに苦労していました。私はそれが動作する場合は試して更新します。説明にあなたの努力を感謝します。 – pythonuser

+0

喜んで助けてください。そうでない場合は教えてください。 – Cynic

関連する問題