如何在pytest fixture中获取参数ID?

时间:2015-08-03 14:54:13

标签: pytest fixtures

是否可以在Pytest灯具中获取参数ID

import pytest

@pytest.fixture(
     params = ['a', 'b', 'c'],
     ids    = ['x', 'y', 'z'])
def foo(request):
   myParam = request.param
   myID    = "How do I get the current ID?"

1 个答案:

答案 0 :(得分:1)

一种方法是将中的ID作为参数传递

import pytest

params = ['a', 'b', 'c']
ids    = ['x', 'y', 'z']
@pytest.fixture(params=zip(params,ids), id=lambda x: x[1]):
def foo(request):
    myParam = request.param[0]
    myID    = request.param[1]

这很难看,但确实有效。