[英]Run setup only once before a test run for a parameterized test in pytest
我想使用一个夹具来为测试设置资源,该测试应该在测试开始之前只创建一次资源,但测试是参数化的。如果我按照下面提到的方式进行操作,它会为 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
fixture 的 scope 设置为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')
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.