给定一个同时具有固定装置和参数化参数的测试函数,如何获取参数化参数及其值的字典?request.node.name
我可以使用or访问序列化的值列表os.environ.get('PYTEST_CURRENT_TEST')
,但这并没有给出参数的相应名称。PyTest 打印它们,但我需要在自定义错误处理挂钩中访问它们。
@pytest.mark.parametrize('a', [False, True])
@pytest.mark.parametrize('b', [1, 2])
def test_foo(request, fixt_y, fixt_z, a, b): # fixt_y/z are some fixtures
print(request.node.name) # e.g., test_foo[0-1-False]
print(os.environ.get('PYTEST_CURRENT_TEST')) # e.g., test_file.py::test_foo[0-1-False] (call)
我想要的是以某种方式{'a': False, 'b': 1}
进入test_foo
。