1、使用pip 安装pytest-repeat
安装命令:pip3 install pytest-repeat -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
2 使用@pytest.mark.repeat(count)装饰器,标记要重复执行的用例,代码如下:
import pytest
class TestCount():
@pytest.mark.repeat(5)
def test_count_01(self):
print("执行测试用例1")
def test_count_02(self):
print("执行测试用例2")
if __name__ == '__main__':
pytest.main(["-s", "-v"])
执行结果如下: