如何将参数传递给用于测试课程设置的课程范围夹具?

时间:2019-08-30 18:14:16

标签: python pytest

我正在尝试将测试从xUnit样式转移到pytest。测试类中的每个方法都需要选项,这些选项在我所有的测试类中都是不同的。我知道我可以使用类范围的固定装置而无需像这样传递参数:

conftest.py
@pytest.fixture(scope="class")
def options(request):
    request.cls.options = component.option_maker(a=1, b=20)

TestClass.py
@pytest.mark.usefixtures('options')
class TestClass(BaseTest):
    ...

我已经看到我可以包装选项夹具:

@pytest.fixture(scope="class")
def options_factory():
    def options(request):
        request.cls.options = component.option_maker(a=1, b=20)

但是如何在测试开始时从TestClass传递参数以用于kwargs a和b?我不想做的是在类的每个方法中调用选项,这似乎浪费了资源。

0 个答案:

没有答案