Python pytest如何制作一个将另一个夹具参数化的夹具

Python pytest如何制作一个将另一个夹具参数化的夹具,python,pytest,fixtures,Python,Pytest,Fixtures,我有很多通过pytest管理的参数化装置 有时,我希望使用夹具的测试不必担心应用参数 是否可以制作一个将另一个夹具参数化的夹具? 导入pytest Foo类: 定义初始化(self,a:int,b:int): 通过 @pytest.fixture def foo(a:int,b:int)->foo: 返回Foo(a,b) @pytest.fixture @pytest.mark.parametize(“a,b”,[(2,3)])#我该怎么做? def fixture_参数化_另一个_fixtur

我有很多通过
pytest
管理的参数化装置

有时,我希望使用夹具的测试不必担心应用参数

是否可以制作一个将另一个夹具参数化的夹具?

导入pytest
Foo类:
定义初始化(self,a:int,b:int):
通过
@pytest.fixture
def foo(a:int,b:int)->foo:
返回Foo(a,b)
@pytest.fixture
@pytest.mark.parametize(“a,b”,[(2,3)])#我该怎么做?
def fixture_参数化_另一个_fixture(foo:foo)->foo:
返回foo
#我不想在这里参数化,我希望夹具已经设置好
使用第二个夹具进行def测试(夹具参数化另一个夹具:Foo):
通过

我不认为您可以按照您想要的方式来执行此操作,但也许将夹具参数与正常功能结合使用就足够了,例如:

。。。
def foo(a:int,b:int)->foo:
返回Foo(a,b)
@pytest.fixture(参数=[(3,2)])
def参数化固件1(请求)->Foo:
生成foo(request.param[0],request.param[1])
@pytest.fixture(参数=[(5,6)、(7,8)])
def参数化固定装置2(请求)->Foo:
生成foo(request.param[0],request.param[1])
带第二个固定装置1的def测试(参数化固定装置1:Foo):
#使用(3,2)进行一次试验
通过
带第二个固定装置2的def测试(参数化固定装置2:Foo):
#两项测试
通过

当然,只有当您想在多个测试中使用相同的参数时,这才有意义。

接下来,我重构了我所有的装置,以使用这种方法。再次感谢@mybeanbreman。我还在
pytest
中打开了一个功能请求,请求提供我希望已经存在的功能。