2017-01-13 12 views
0

私はPythonを使用しています&自動化のためにBDDを動作させてください。Behave BDDのバックグラウンドで手順をスキップする方法はありますか?

私が知っているように、各シナリオの前にバックグラウンドが実行されますが、前もって@need_backgroundタグでシナリオを実行するにはバックグラウンドが必要です。どうすればこれを達成できますか?

私は現在のシナリオタグとif tag != need_background then skip background's stepsを取得しようとしました。しかし、振る舞いには、私が知っている限り、バックグラウンドステップをスキップする方法はありません。

答えて

1

シナリオは同じ背景を共有していないので、特別なものを他の機能ファイルに移動したり、背景を使用しないようにしてください。

def before_scenario(context, scenario): 
if 'need_background ' in scenario.tags: 
    context.if_background = True 
else: 
    context.if_background = False  

そして、一歩

として、バックグラウンドですべてのステップを組み合わせて、まず

をごenvironment.pyにフックを追加:あなたはまだ背景セクションを使用したい場合は

しかし、私が推薦します

@given('all background steps are done') 
def step_impl(context): 
if context.if_background: 
    context.context.execute_steps(''' 
     steps in background 
    ''') 
else: 
    pass 

今、あなたの機能ファイルがある場合:

Feature: Background with condition 
Background: 
Given all background steps are done 

Scenario: run without background 
# steps of the scenario you don't need background 

@need_background 
Scenario: run with background 
# steps of the scenario you need background 

あなたの要件を満たしている可能性があります

関連する問題