当前位置: 首页 > news >正文

大连建设工程信息网官网官网官免费网站建设seo

大连建设工程信息网官网官网官,免费网站建设seo,个人签名设计网站,虚拟主机怎么做网站前言 httprunner 用 yaml 文件实现接口自动化框架很好用#xff0c;最近在看 pytest 框架#xff0c;于是参考 httprunner的用例格式#xff0c;写了一个差不多的 pytest 版的简易框架 项目结构设计 项目结构完全符合 pytest 的项目结构#xff0c;pytest 是查找 test_.…前言 httprunner 用 yaml 文件实现接口自动化框架很好用最近在看 pytest 框架于是参考 httprunner的用例格式写了一个差不多的 pytest 版的简易框架 项目结构设计 项目结构完全符合 pytest 的项目结构pytest 是查找 test_.py 文件我这里是查找 test_.yml 文件唯一不同的就是这个地方 以前写test_*.py 的测试用例现在完全不用写了全部写yaml 文件就行项目结构参考 只需在 conftest.py 即可实现代码量超级少 pytest 7.x最新版 def pytest_collect_file(parent, file_path):# 获取文件.yml 文件,匹配规则if file_path.suffix .yml and file_path.name.startswith(test):return YamlFile.from_parent(parent, pathfile_path) pytest 5.x以上版本 import pytest import requestsdef pytest_collect_file(parent, path):# 获取文件.yml 文件,匹配规则if path.ext .yml and path.basename.startswith(test):# print(path)# print(parent)# return YamlFile(path, parent)return YamlFile.from_parent(parent, fspathpath)class YamlFile(pytest.File):# 读取文件内容def collect(self):import yamlraw yaml.safe_load(self.fspath.open(encodingutf-8))for yaml_case in raw:name yaml_case[test][name]values yaml_case[test]yield YamlTest.from_parent(self, namename, valuesvalues)class YamlTest(pytest.Item):def __init__(self, name, parent, values):super(YamlTest, self).__init__(name, parent)self.name nameself.values valuesself.request self.values.get(request)self.validate self.values.get(validate)self.s requests.session()def runtest(self):# 运行用例request_data self.values[request]# print(request_data)response self.s.request(**request_data)print(\n, response.text)# 断言self.assert_response(response, self.validate)def assert_response(self, response, validate):设置断言import jsonpathfor i in validate:if eq in i.keys():yaml_result i.get(eq)[0]actual_result jsonpath.jsonpath(response.json(), yaml_result)expect_result i.get(eq)[1]print(实际结果%s % actual_result)print(期望结果%s % expect_result)assert actual_result[0] expect_resultpytest 4.x 以下版本 import pytest import requests # 作者-上海悠悠 QQ交流群:717225969 # blog地址 https://www.cnblogs.com/yoyoketang/def pytest_collect_file(parent, path):# 获取文件.yml 文件,匹配规则if path.ext .yml and path.basename.startswith(test):# print(path)# print(parent)return YamlFile(path, parent)class YamlFile(pytest.File):# 读取文件内容def collect(self):import yamlraw yaml.safe_load(self.fspath.open(encodingutf-8))for yaml_case in raw:name yaml_case[test][name]values yaml_case[test]yield YamlTest(name, self, values)class YamlTest(pytest.Item):def __init__(self, name, parent, values):super(YamlTest, self).__init__(name, parent)self.name nameself.values valuesself.request self.values.get(request)self.validate self.values.get(validate)self.s requests.session()def runtest(self):# 运行用例request_data self.values[request]# print(request_data)response self.s.request(**request_data)print(\n, response.text)# 断言self.assert_response(response, self.validate)def assert_response(self, response, validate):设置断言import jsonpathfor i in validate:if eq in i.keys():yaml_result i.get(eq)[0]actual_result jsonpath.jsonpath(response.json(), yaml_result)expect_result i.get(eq)[1]print(实际结果%s % actual_result)print(期望结果%s % expect_result)assert actual_result[0] expect_result 断言这部分目前只写了判断相等仅供参考支持jsonpath来提取json数据 yaml格式的用例 在项目的任意目录只要是符合test_开头的yml文件我们就认为是测试用例 test_login.yml的内容如下 - test:name: login case1request:url: http://49.235.x.x:7000/api/v1/login/method: POSTheaders:Content-Type: application/jsonUser-Agent: python-requests/2.18.4json:username: testpassword: 123456validate:- eq: [$.msg, login success!]- eq: [$.code, 0]- test:name: login case2request:url: 49.235.x.x:7000/api/v1/login/method: POSTheaders:Content-Type: application/jsonUser-Agent: python-requests/2.18.4json:username: testpassword: 123456validate:- eq: [$.msg, login success!]- eq: [$.code, 0] 运行用例 运行用例完全符合pytest的只需用例风格支持allure报告 pytest -v D:\soft\api_pytest_1208pytest -vtest session starts platform win32 -- Python 3.6.6, pytest-4.5.0, py-1.9.0, cachedir: .pytest_cache rootdir: D:\soft\api_pytest_1208 plugins: allure-pytest-2.8.6 collected 4 itemsdata/test_login.yml::login case1 PASSED [ 25%] data/test_login.yml::login case2 PASSED [ 50%] data/test_login1.yml::login case1 PASSED [ 75%] data/test_login1.yml::login case2 PASSED [100%] 4 passed in 1.34 seconds allure报告 pytest --alluredir ./report 目前是把 yaml 文件下每个 test 当一个用例执行后续还可以加上提取参数参数关联更高级的功能 这可能是B站最详细的pytest自动化测试框架教程整整100小时全程实战
http://www.hkea.cn/news/14479345/

相关文章:

  • 网站备案编号小程序需不需要服务器
  • 哈尔滨响应式网站建设公司图片类网站模板
  • 网站开发技术课程设计说明书网页设计公司联系方式
  • 重庆城市建设集团官方网站手机网站建设事项
  • 大学做兼职英语作文网站点击下载app安装
  • 苏州高端网站建设企业作业页面设计模板
  • 网站设计的原则有哪些wordpress latex公式
  • 怎样建立网站快捷方式莘县住房建设局网站
  • 厦门手机网站建设是什么梅江区建设局网站
  • 深圳做网站在去那备案有没有卖设计的网站
  • 主机怎么做网站二次跳转跨境电商数据在哪个官网查
  • 网站建设必要性在线代理浏览器网站
  • 网站建设方案解救苏州久远网络jquery个人网站开发
  • 衡阳网站建设icp备网站英文域名
  • 中学教材数字化学习资源的建设——教材配套网站的设计及发展趋势泗县口碑营销互联网营销推荐咨询
  • 南通公司做网站怎样建设微网站
  • 洛阳建站公司效果wordpress注册用户验证
  • 公司网站建设的项目工作分解结构网站动画特效
  • 免费建工作室网站软件开发外包大概多少钱
  • 网站教育培训机构排名政务公开与网站建设的矛盾
  • 温州网站建设定制手机网站设计欣赏
  • 网站建设的收费影视传媒宣传片
  • 网络网站设计培训商丘软件开发
  • 做网站公司销售开场白官方微网站吗
  • 网站商场系统软件如何让百度抓取网站
  • 网站开发工作总结wordpress流量统计插件
  • 蒙古文网站建设工作情况汇报wordpress nodejs版本
  • 响应式网站建设视频教程常用的搜索引擎有哪些?
  • 网站前端页面设计竹子建站模板怎么下载
  • 做网站 视频加载太慢新网域名续费