一、前言
平常在做功能测试的时候,经常会遇到某个模块不稳定,偶然会出现一些bug,对于这种问题我们会针对此用例反复执行多次,最终复现出问题来。
自动化运行用例时候,也会出现偶然的bug,可以针对单个用例,或者针对某个模块的用例重复执行多次。
二、pytest-repeat
pytest-repeat是pytest的一个插件,用于重复执行单个用例,或多个测试用例,并指定重复次数
使用--count命令行选项指定要运行测试用例和测试次数
pytest --count=10 test_file.py
三、重复执行--count
#!encoding=utf-8
import pytest
#fixture
@pytest.fixture()
def first():
print('获取用户名')
username='xiaoluo'
return username
@pytest.fixture()
def second(first): #fixture调用其他fixture
getuser=first
getpwd='123456'
return (getuser,getpwd)
#用例执行,调用fixture
def test_1(second):
print('测试账号为{},密码为{}'.format(second[0],second[1]))
assert second[0]=='xiaoluo'
输入命令:重复运行5次