创建一个启动文件,你可以叫他debug.py
注意:启动程序一定要放在if __name__ == "__main__":内运行

  1. # debug.py
  2. from autoTestScheme import run, conf, logger
  3. if __name__ == "__main__":
  4. run = run.Run()
  5. run.set_logger(logger_folder_name='logs', is_allure=is_formal)
  6. run.load_case('data')
  7. run.load_allure_tmp('allure-results')
  8. run.run()
  9. run.get_report('allure')
  10. run.send_report_by_feishu(link, '每日巡检报告', is_at_all=True)

config目录

.env环境

  1. export ENV=test

test.toml

  1. [test]
  2. name = "au"
  3. [test.run]
  4. name = "测试环境"
  5. test_tags = ['test']
  6. test_case = 'all'
  7. is_debug = true
  8. [test.request]
  9. subdomain = "www"
  10. base_url = "httpbin.org"
  11. agreement = "http"
  12. api = [['api']]
  13. [testio.sql]
  14. host = "172.0.0.1"
  15. user = "root"
  16. password = "xxxx"
  17. port = 3306
  18. [testio.redis]
  19. host = "172.0.0.1"
  20. port = 6379
  21. decode_responses = true
  22. [test.robot]
  23. type = "feishu"
  24. func = "send_lark_report"
  25. report_link = "xxxxxxxx"
  26. [test.feishu]
  27. url = "https://open.larksuite.com/open-apis/bot/v2/hook"
  28. access_token = "xxxxxx"

API数据

api/get.json

  1. {
  2. "id": "get",
  3. "title": "获取",
  4. "method": "GET",
  5. "params": {},
  6. "data": {},
  7. "headers": {},
  8. "path": "/get"
  9. }

data 数据

test_01.json

  1. [
  2. {
  3. "__file": "test_01",
  4. "__func": "test_01",
  5. "__dependent_class": null
  6. },
  7. {
  8. "title": "法币交易-买BTC-参数合法",
  9. "tags": ["test", "debug"],
  10. "params": {
  11. },
  12. "outs": {
  13. "args": {},
  14. "headers": {
  15. "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",
  16. "Accept-Encoding": "gzip, deflate",
  17. "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
  18. "Host": "httpbin.org",
  19. "Upgrade-Insecure-Requests": "1",
  20. "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",
  21. "X-Amzn-Trace-Id": "Root=1-61ce64f0-2192d80500d3f3f97ffd66b6"
  22. },
  23. "origin": "221.12.20.5",
  24. "url": "http://httpbin.org/get"
  25. }
  26. }
  27. ]

BASE

  1. from autoTestScheme.case import Base
  2. from buiness import Buiness # 此处替换为自己业务类
  3. # 使用方式详见Base,需要注意的是,最好在setup_class内进行hook的注册,见settings特殊说明
  4. # 用例框架请使用pytest框架结构
  5. class TestBase(Base, Buiness):
  6. def setup_class(self):
  7. """
  8. 前置条件
  9. :return:
  10. """
  11. ...

Case

  1. # test_create.py 文件名不要重复
  2. class TestCase(TestBase):
  3. def test_io(self, data_conversion, data):
  4. params, outs = data_conversion.get('params', 'outs')
  5. response = self.settings.request.send("get", params=params)
  6. self.check_response(response, outs)
  7. # 本处只讲精简版
  8. # 方法必须定义入参data_conversion, data
  9. # 位置随意