小编Dha*_*hta的帖子

如何在 pytest 中迭代 test_function 以获得多个值?

我想知道如何在 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 个测试用例。我怎样才能实现它?

python linux integration-testing pytest python-unittest

4
推荐指数
1
解决办法
1518
查看次数