Dha*_*hta 4 python linux integration-testing pytest python-unittest
我想知道如何在 pytest 中迭代 test_funtion() 以获得不同的值?例如。
list = ['ls','ps', 'df' ,'du'] #list of Linux commands
def test_method(self):
for I in list:
r=subprocess.check_output(I)
if r:
assert True
else:
assert False
Run Code Online (Sandbox Code Playgroud)
现在,当我运行 pytest -k test_method 时,它显示仅通过了一个测试用例。但我希望所有 4 个案例都使用单个函数运行,并且需要在输出中传递 4 个测试用例。我怎样才能实现它?
扩展@Nithin-Mohan 之前的回答
commands = ['ls','ps', 'df' ,'du'] #list of Linux commands
@pytest.mark.parametrize("cmds",commands)
def test_method(cmds):
r=subprocess.check_output(cmds)
if r:
assert True
else:
assert False
Run Code Online (Sandbox Code Playgroud)
这是作为 4 个单独测试运行的输出
test_sflow.py::test_method[ls] PASSED [ 25%]
test_sflow.py::test_method[ps] PASSED [ 50%]
test_sflow.py::test_method[df] PASSED [ 75%]
test_sflow.py::test_method[du] PASSED [ 100%]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1518 次 |
| 最近记录: |