我想要三个固定装置。它们用于设置测试的配置,并指定哪些测试使用哪些配置。
这三个固定装置应该是: release_configs dev_configs all_configs
如果测试使用了夹具"all_configs",它将为每个配置会话运行进行测试。如果一个测试使用了夹具"dev_configs",那么它将只对某个子集进行测试。如果测试使用夹具"release_configs",则只对其他子集进行测试。
all_configs包含开发和发布的总和。
这个是可能的吗?
下面是我对all_configs的看法:
@pytest.fixture(autouse=False, scope="session", params=release_configs_to_test+dev_configs_to_test, ids=release_configs_to_test+dev_configs_to_test)
def all_configs(self, request):
name = request.param
print('config fixture called')
self._setup_config(name)
yield name
其中release_configs_to_test和dev_configs_to_test只是字符串列表(配置名称)
编辑:
这似乎是一个与Chaining pytest fixtures类似的问题,而这个问题还没有解决。
然而,这个问题是试图过滤夹具,而我试图组合它们。
然而,这两种选择都是可行的。
发布于 2022-11-08 15:53:06
Pytest夹具可以“请求”其他夹具,这些夹具可以用于组合、过滤或其他处理。
https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#fixtures-can-request-other-fixtures
# Arrange
@pytest.fixture
def first_entry():
return "a"
# Arrange
@pytest.fixture
def order(first_entry):
return [first_entry]
def test_string(order):
# Act
order.append("b")
# Assert
assert order == ["a", "b"]
https://stackoverflow.com/questions/60423342
复制相似问题