我有以下测试场景:
以下是实现此目的的示例代码:场景:
@fixture.remove_edited_project
@web
Scenario: Edit a project data
Given Project was created with the following parameters
| project_name |
| my_project_to_edit |
When I edit the "my_project_to_edit" project
Then Project is edited
将数据保存到要在拆解功能(夹具)中使用的某个变量中的步骤:
@step('I edit the "{project_name}" project')
def step_impl(context, project_name):
# steps related to editing the project
# storing value in context variable to be used in fixture
context.edited_project_name = project_name
以及在场景之后删除项目的示例夹具功能:
@fixture
def remove_edited_project(context):
yield
logging.info(f'Removing project: "{context.edited_project_name}"')
# Part deleting a project with name stored in context.edited_project_name
在这种配置下,一切正常,在任何情况下(测试失败或通过),项目都将被夹具删除。没关系。
但是,当我想在功能级别执行这样的功能时,意味着在功能关键字之前放置@fixture.remove_edited_project
装饰器:
@fixture.remove_edited_project
Feature: My project Edit feature
,那么这是行不通的。我已经知道原因了-在每种情况下都会清理context.edited_project_name变量,以后不再可用于此Fixture函数。
是否有某种方法可以将参数以某种方式传递到特征级别的夹具?在全球范围内?我试图使用全局变量作为选项,但是在此框架中开始有点脏和成问题。
理想情况下,应该有@fixture.edited_project_name('my_project_to_edit')
之类的东西>
我有以下测试场景:检查是否创建了具有特定名称的项目编辑此项目验证它已被编辑,作为拆解过程的一部分,删除该项目这里是...