【发布时间】:2021-02-02 18:28:01
【问题描述】:
我知道,在behave 中,可以使用environment.py 指定before_feature() 和after_feature() 函数在每个 功能之前或之后执行设置和拆卸代码。
但是,有没有办法指定仅针对特定功能执行的自定义后功能功能?
在我的在线搜索中,我发现一些页面讨论了使用 cucumber-jvm 执行此操作的可能方法,但没有关于使用行为进行此操作的内容:
- Getting @BeforeAll and @AfterAll behaviour with Cucumber JVM and JUnit
- Add @BeforeAll and @AfterAll hooks cucumber-jvm GitHub issue
- cucumber-jvm global hook workarounds
举个例子,我想做类似的事情:
Feature: My feature
AfterFeature:
Then Database is reset
# Scenarios
我想到的一件事可能是context 可以在“全局”after_feature() 函数中查看,然后如果该功能的名称与所需名称匹配,则可以运行自定义代码。例如,类似:
# In environment.py
def after_all(context):
if context.feature.name == 'feature_with_custom_teardown.feature':
# Do custom teardown
# Do regular teardown
但是,当我尝试在 after_all() 函数中检查 context 时,由于某种原因,该功能是 None - 但这可能只是意味着我做错了。
【问题讨论】:
标签: python cucumber bdd python-behave