创建一个启动文件,你可以叫他debug.py
注意:启动程序一定要放在if __name__ == "__main__":
内运行
# debug.py
from autoTestScheme import run, conf, logger
if __name__ == "__main__":
run = run.Run()
run.set_logger(logger_folder_name='logs', is_allure=is_formal)
run.load_case('data')
run.load_allure_tmp('allure-results')
run.run()
run.get_report('allure')
run.send_report_by_feishu(link, '每日巡检报告', is_at_all=True)
config目录
.env环境
export ENV=test
test.toml
[test]
name = "au"
[test.run]
name = "测试环境"
test_tags = ['test']
test_case = 'all'
is_debug = true
[test.request]
subdomain = "www"
base_url = "httpbin.org"
agreement = "http"
api = [['api']]
[testio.sql]
host = "172.0.0.1"
user = "root"
password = "xxxx"
port = 3306
[testio.redis]
host = "172.0.0.1"
port = 6379
decode_responses = true
[test.robot]
type = "feishu"
func = "send_lark_report"
report_link = "xxxxxxxx"
[test.feishu]
url = "https://open.larksuite.com/open-apis/bot/v2/hook"
access_token = "xxxxxx"
API数据
api/get.json
{
"id": "get",
"title": "获取",
"method": "GET",
"params": {},
"data": {},
"headers": {},
"path": "/get"
}
data 数据
test_01.json
[
{
"__file": "test_01",
"__func": "test_01",
"__dependent_class": null
},
{
"title": "法币交易-买BTC-参数合法",
"tags": ["test", "debug"],
"params": {
},
"outs": {
"args": {},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Host": "httpbin.org",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36",
"X-Amzn-Trace-Id": "Root=1-61ce64f0-2192d80500d3f3f97ffd66b6"
},
"origin": "221.12.20.5",
"url": "http://httpbin.org/get"
}
}
]
BASE
from autoTestScheme.case import Base
from buiness import Buiness # 此处替换为自己业务类
# 使用方式详见Base,需要注意的是,最好在setup_class内进行hook的注册,见settings特殊说明
# 用例框架请使用pytest框架结构
class TestBase(Base, Buiness):
def setup_class(self):
"""
前置条件
:return:
"""
...
Case
# test_create.py 文件名不要重复
class TestCase(TestBase):
def test_io(self, data_conversion, data):
params, outs = data_conversion.get('params', 'outs')
response = self.settings.request.send("get", params=params)
self.check_response(response, outs)
# 本处只讲精简版
# 方法必须定义入参data_conversion, data
# 位置随意