是否可以从夹具请求中检索其他请求的夹具?

时间:2015-08-01 11:13:30

标签: python pytest

例如:

println()

我能用当前版本的Pytest做到吗 - 根据非等级方式的其他灯具制作灯具吗?

1 个答案:

答案 0 :(得分:1)

你可以这样做:

@pytest.fixture()
def fixture1():
    return 'fixture1'


@pytest.fixture()
def fixture2(request):
    if 'fixture1' in request._funcargs:
        # fixture1 was requested earlier
        # but most likely you don't need that check because getfuncargvalue always works
        fixture1_instance = request.getfuncargvalue('fixture1')
    return do_stuff(fixture1_instance)


def test_whatever(fixture1, fixture2):
    result = do_some_stuff(fixture1)
    assert result.supermethod(fixture2)