シナリオは同じ背景を共有していないので、特別なものを他の機能ファイルに移動したり、背景を使用しないようにしてください。
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
あなたの要件を満たしている可能性があります