2017-01-13 1 views
0

파이썬을 사용하고 있습니다 & 자동화를 위해 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 

고객님의 요구 사항을 충족시킬 수 있다고 생각합니다

관련 문제