增加失败重跑机制,优化用例初始化方式

@pytest.mark.parametrize 参数化方式 替换成了 conftest.py文件中的@pytest.fixture(params=ReadFile.read_testcase()), 增加了用例失败重跑机制,重跑次数3,每次间隔时间5秒
This commit is contained in:
zy7y 2020-12-16 10:08:00 +08:00 committed by Gitee
parent 6120aa3ee8
commit 2c356a764f
1 changed files with 9 additions and 6 deletions

View File

@ -20,8 +20,6 @@ from tools.read_file import ReadFile
report = ReadFile.read_config('$.file_path.report')
logfile = ReadFile.read_config('$.file_path.log')
# 读取excel数据对象
cases = ReadFile.read_testcase()
class TestApi:
@ -36,10 +34,15 @@ class TestApi:
os.system(f'allure generate {report}/data -o {report}/html --clean')
logger.success('报告已生成')
@pytest.mark.parametrize('case', cases)
def test_main(self, case, get_db):
# https://www.cnblogs.com/shouhu/p/12392917.html
# reruns 重试次数 reruns_delay 次数之间的延时设置(单位:秒)
# 失败重跑,会影响总测试时长,如不需要 将 @pytest.mark.flaky(reruns=3, reruns_delay=5) 注释即可
@pytest.mark.flaky(reruns=3, reruns_delay=5)
def test_main(self, cases, get_db):
# 此处的cases入参来自与 conftest.py 文件中 cases函数与直接使用 @pytest.mark.parametrize
# 有着差不多的效果
# 发送请求
response, expect, sql = BaseRequest.send_request(case)
response, expect, sql = BaseRequest.send_request(cases)
# 执行sql
DataProcess.handle_sql(sql, get_db)
# 断言操作
@ -47,4 +50,4 @@ class TestApi:
if __name__ == '__main__':
TestApi.run()
TestApi.run()