tests_arr = ['test1','test2']
logs_arr = ['log1','log2']
def List_of_Tests():
tests = tests_arr
return tests
def List_of_Logs():
logs = logs_arr
return logs
@pytest.mark.parametrize("test, log",
[
([i for i in List_of_Tests()], [i for i in List_of_Logs()])
]
)
def methodname(test,log):
print(test+ " " + log)
当我尝试动态地浏览列表项目时,我会得到以下错误
TypeError:应为str、字节或os。PathLike对象,不列出
我不确定你想要什么参数化,但我想:
test_foo/test_stuff.py::test_stuff[test1-log1] PASSED [ 50%]
test_foo/test_stuff.py::test_stuff[test2-log2] PASSED [100%]
那么你应该使用zip。
import pytest
tests_arr = ['test1','test2']
logs_arr = ['log1','log2']
def List_of_Tests():
return tests_arr
def List_of_Logs():
return logs_arr
@pytest.mark.parametrize("test, log", zip(List_of_Tests(), List_of_Logs()))
def test_stuff(test, log):
pass
但是您正在做的事情看起来很奇怪,您是否考虑过使用pytest_generate_tests?