pytest--重复执行用例 pytest-repeat

使用pip安装pytest-repeat 

 pip install pytest -repeat

重复执行--count

命令行执行:pytest baidu/test_1_baidu.py -s --count=5 

文件中写参数执行

在代码中标记要重复多次的测试

@pytest.mark.repeat(1000)

--repeat-scope

--repeat-scope类似于pytest fixture的scope参数,--repeat-scope也可以设置参数: session , moduleclass或者function(默认值)

  • function(默认)范围针对每个用例重复执行,再执行下一个用例
  • class 以class为用例集合单位,重复执行class里面的用例,再执行下一个
  • module 以模块为单位,重复执行模块里面的用例,再执行下一个
  • session 重复整个测试会话,即所有收集的测试执行一次,然后所有这些测试再次执行等等

使用--repeat-scope=session重复执行整个会话用例

如:pytest  test_1_baidu.py -s --count=5 --repeat-scope=session

原文地址:https://www.cnblogs.com/jodie2019/p/13235032.html