运行 在测试前仅设置一次 运行 用于 pytest 中的参数化测试

Run setup only once before a test run for a parameterized test in pytest

我想使用夹具为测试设置资源,它应该在测试开始前只创建一次资源,但测试是 parameterized.If 我正在按照下面提到的方式来调用夹具xx 和 yy 的每一个组合,谁能帮我用另一种方法来实现这个目标?

@pytest.mark.usefixtures('create_files')
@pytest.mark.parametrize('xx', ['a', 'b', 'c'])
@pytest.mark.parametrize('yy', ['1', '2', '3'])
def test_operaration(self):
    .
    .
    .
    .

还有什么方法可以将 xx 和 yy 的值传递给每个 运行 的 create_files fixture ?

create_files 夹具的范围设置为 session:

@pytest.fixture(scope='session')
def create_files():
    ...

最终这有助于解决我的问题:

@pytest.fixture(scope='function')
def create_files(request: FixtureRequest):
    xx = request.getfixturevalue('xx')
    yy = request.getfixturevalue('yy')
    ...