是否可以在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?"
答案 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]
这很难看,但确实有效。