【发布时间】:2021-06-16 16:12:59
【问题描述】:
import pytest
@pytest.fixture()
def fixture1(fixture_a):
print('In fixture 1')
<do>
step a
step b
<end>
return <some object1>
@pytest.fixture()
def fixture2(fixture_b):
print('In fixture 2')
<do>
step x
step y
<end>
return <some object2>
def decide():
a = 1
if a == 1:
return fixture1: Object1
else:
return fixture2: Object2
def test_me():
res = decide()
assert res == Object
我有两个夹具 arg1 和 arg2,现在我想将其中一个夹具返回给测试,但这必须是基于条件的动态选择。如何做到这一点?
更新:fixture arg1 和 arg2 有一个依赖链,它们被用于不同的测试。
另外,决定函数需要在多个测试中使用。
【问题讨论】:
标签: python python-3.x pytest