시나리오가 동일한 배경을 공유하지 않기 때문에 특수한 파일을 다른 기능 파일로 이동하거나 배경을 사용하지 않는 것이 좋습니다.
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
고객님의 요구 사항을 충족시킬 수 있다고 생각합니다