如何在 Python Behave 中跳过场景及其应用示例:
所有函数都必须在 environment.py 模块中声明:
环境.py
在 before_all() 中声明 skip_scenario = True
添加一个skip_scenarios=True来控制跳过各种特征文件中的特定场景。控制器在environment.py的before_all函数中设置>**
def before_all(context):
pass
context.scenario_metadata_dict = {}
context.feature_metadata = {'skip_scenario': True}
在 before_scenario() 中添加条件:
如果特征文件中的任何场景包含标签“environmentSkip”并且skip_scenario = True则只跳过那些场景。
def before_scenario(context, scenario):
if context.feature_metadata['skip_scenario'] and "environmentSkip" in scenario.effective_tags:
scenario.skip("Marked with skip from environment Control")
return
elif "skip" in scenario.effective_tags:
scenario.skip("Marked with @skip tag in feature File")
return
功能文件:
如果您希望在特定场景中跳过标记,则将具有标记 @environmentSkip 标记。
@system-testing @regression @environmentSkip
Scenario: validate Global Exclusion Rules for PrimaryEarlyLifeCLI Strategy
When derive the expected Results for global Exclusion rule NEGESTAT
| KEY | VALUE |
|test_scenario_id |TS1_GlobalExclusion_NEGESTAT|
注意:上面的示例处理了跳过场景,处理跳过的自然方式和受控处理跳过。
应用程序
自然方式:将帮助开发人员跳过用于调试目的的场景。
受控方式:将有助于控制特定环境的场景。
如果需要,也可以为 before_feature() 添加相同的控件。