forked from DxvLwRYF/apiAutoTest
增加主运行文件run.py
This commit is contained in:
parent
d2665b5bc6
commit
3e0550186c
|
@ -113,7 +113,7 @@ https://www.bilibili.com/video/BV1EE411B7SU?p=10
|
||||||
#### 测试报告
|
#### 测试报告
|
||||||
|
|
||||||

|

|
||||||
|

|
||||||
#### 更新
|
#### 更新
|
||||||
2020/08/08 增加实际响应存储数据的方法,并在字典可以处理依赖见tools/svae_response.py
|
2020/08/08 增加实际响应存储数据的方法,并在字典可以处理依赖见tools/svae_response.py
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ https://www.bilibili.com/video/BV1EE411B7SU?p=10
|
||||||
|
|
||||||
2020/12/08 优化断言信息,增加数据库(支持mysql)查询操作, 使用`@pytest.fixture(scope="session")`来托管数据库对象,用例新增sql栏
|
2020/12/08 优化断言信息,增加数据库(支持mysql)查询操作, 使用`@pytest.fixture(scope="session")`来托管数据库对象,用例新增sql栏
|
||||||
|
|
||||||
|
2020/12/16 使用conftest.py 初始化用例, 增加失败重跑机制, 增加运行文件run,优化test_api.py冗余代码
|
||||||
#### 博客园首发
|
#### 博客园首发
|
||||||
https://www.cnblogs.com/zy7y/p/13426816.html
|
https://www.cnblogs.com/zy7y/p/13426816.html
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ expr:
|
||||||
token: $.data.token
|
token: $.data.token
|
||||||
|
|
||||||
file_path:
|
file_path:
|
||||||
test_case: ../data/case_data.xlsx
|
test_case: data/case_data.xlsx
|
||||||
report: ../report/
|
report: report/
|
||||||
log: ../log/run{time}.log
|
log: log/run{time}.log
|
||||||
|
|
||||||
email:
|
email:
|
||||||
# 发件人邮箱
|
# 发件人邮箱
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env/python3
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
@project: apiAutoTest
|
||||||
|
@author: zy7y
|
||||||
|
@file: run.py
|
||||||
|
@ide: PyCharm
|
||||||
|
@time: 2020/12/16
|
||||||
|
@github: https://github.com/zy7y
|
||||||
|
@site: https://cnblogs.com/zy7y
|
||||||
|
@desc: 运行文件
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from test.conftest import pytest
|
||||||
|
from tools import logger
|
||||||
|
from tools.read_file import ReadFile
|
||||||
|
|
||||||
|
report = ReadFile.read_config('$.file_path.report')
|
||||||
|
logfile = ReadFile.read_config('$.file_path.log')
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
if os.path.exists('report/'):
|
||||||
|
shutil.rmtree(path='report/')
|
||||||
|
logger.add(logfile, enqueue=True, encoding='utf-8')
|
||||||
|
logger.info('开始测试...')
|
||||||
|
pytest.main(args=['test/test_api.py', f'--alluredir={report}/data'])
|
||||||
|
os.system(f'allure generate {report}/data -o {report}/html --clean')
|
||||||
|
logger.success('报告已生成')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
|
@ -8,46 +8,22 @@
|
||||||
@time: 2020/11/22
|
@time: 2020/11/22
|
||||||
@desc: 测试方法
|
@desc: 测试方法
|
||||||
"""
|
"""
|
||||||
import os
|
from .conftest import pytest
|
||||||
import shutil
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from tools import logger
|
|
||||||
from api.base_requests import BaseRequest
|
from api.base_requests import BaseRequest
|
||||||
from tools.data_process import DataProcess
|
from tools.data_process import DataProcess
|
||||||
from tools.read_file import ReadFile
|
|
||||||
|
|
||||||
report = ReadFile.read_config('$.file_path.report')
|
|
||||||
logfile = ReadFile.read_config('$.file_path.log')
|
|
||||||
|
|
||||||
|
|
||||||
class TestApi:
|
# https://www.cnblogs.com/shouhu/p/12392917.html
|
||||||
|
# reruns 重试次数 reruns_delay 次数之间的延时设置(单位:秒)
|
||||||
@classmethod
|
# 失败重跑,会影响总测试时长,如不需要 将 @pytest.mark.flaky(reruns=3, reruns_delay=5) 注释即可
|
||||||
def run(cls):
|
# @pytest.mark.flaky(reruns=2, reruns_delay=1)
|
||||||
if os.path.exists('../report'):
|
def test_main(cases, get_db):
|
||||||
shutil.rmtree(path='../report')
|
# 此处的cases入参来自与 conftest.py 文件中 cases函数,与直接使用 @pytest.mark.parametrize
|
||||||
logger.add(logfile, enqueue=True, encoding='utf-8')
|
# 有着差不多的效果
|
||||||
logger.info('开始测试...')
|
# 发送请求
|
||||||
pytest.main(args=[f'--alluredir={report}/data'])
|
response, expect, sql = BaseRequest.send_request(cases)
|
||||||
os.system(f'allure generate {report}/data -o {report}/html --clean')
|
# 执行sql
|
||||||
logger.success('报告已生成')
|
DataProcess.handle_sql(sql, get_db)
|
||||||
|
# 断言操作
|
||||||
# https://www.cnblogs.com/shouhu/p/12392917.html
|
DataProcess.assert_result(response, expect)
|
||||||
# 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(cases)
|
|
||||||
# 执行sql
|
|
||||||
DataProcess.handle_sql(sql, get_db)
|
|
||||||
# 断言操作
|
|
||||||
DataProcess.assert_result(response, expect)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
TestApi.run()
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class ReadFile:
|
||||||
config_dict = None
|
config_dict = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_config_dict(cls, config_path: str = '../config/config.yaml') -> dict:
|
def get_config_dict(cls, config_path: str = 'config/config.yaml') -> dict:
|
||||||
"""读取配置文件,并且转换成字典
|
"""读取配置文件,并且转换成字典
|
||||||
:param config_path: 配置文件地址, 默认使用当前项目目录下的config/config.yaml
|
:param config_path: 配置文件地址, 默认使用当前项目目录下的config/config.yaml
|
||||||
return cls.config_dict
|
return cls.config_dict
|
||||||
|
@ -53,4 +53,3 @@ class ReadFile:
|
||||||
value.pop(3)
|
value.pop(3)
|
||||||
data_list.append(list(value))
|
data_list.append(list(value))
|
||||||
return data_list
|
return data_list
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue