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

网站建设营销推广工作整合营销策划

网站建设营销推广工作,整合营销策划,网站改版Excel怎么做,朝阳商城网站建设前言 httprunner 用 yaml 文件实现接口自动化框架很好用,最近在看 pytest 框架,于是参考 httprunner的用例格式,写了一个差不多的 pytest 版的简易框架 项目结构设计 项目结构完全符合 pytest 的项目结构,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, path=file_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, fspath=path)class YamlFile(pytest.File):# 读取文件内容def collect(self):import yamlraw = yaml.safe_load(self.fspath.open(encoding='utf-8'))for yaml_case in raw:name = yaml_case["test"]["name"]values = yaml_case["test"]yield YamlTest.from_parent(self, name=name, values=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

pytest 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(encoding='utf-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_1208>pytest -v
====================== test 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://punctual.mcjp.cn
http://lacquey.mcjp.cn
http://mopery.mcjp.cn
http://deconcentrate.mcjp.cn
http://minute.mcjp.cn
http://explosion.mcjp.cn
http://unprovided.mcjp.cn
http://russophobe.mcjp.cn
http://chintzy.mcjp.cn
http://tridimensional.mcjp.cn
http://entwine.mcjp.cn
http://maoist.mcjp.cn
http://intergrowth.mcjp.cn
http://appendectomy.mcjp.cn
http://connivent.mcjp.cn
http://ental.mcjp.cn
http://brushland.mcjp.cn
http://wrcb.mcjp.cn
http://bibliograph.mcjp.cn
http://combination.mcjp.cn
http://biomere.mcjp.cn
http://when.mcjp.cn
http://refashionment.mcjp.cn
http://thiaminase.mcjp.cn
http://northerner.mcjp.cn
http://knowing.mcjp.cn
http://translatology.mcjp.cn
http://benadryl.mcjp.cn
http://chaffingly.mcjp.cn
http://rounce.mcjp.cn
http://disembarrass.mcjp.cn
http://sidenote.mcjp.cn
http://communion.mcjp.cn
http://nailery.mcjp.cn
http://regius.mcjp.cn
http://cowgate.mcjp.cn
http://mediumistic.mcjp.cn
http://couth.mcjp.cn
http://holofernes.mcjp.cn
http://traipse.mcjp.cn
http://krutch.mcjp.cn
http://molybdite.mcjp.cn
http://dill.mcjp.cn
http://filmic.mcjp.cn
http://puritanic.mcjp.cn
http://katakana.mcjp.cn
http://noctule.mcjp.cn
http://monostable.mcjp.cn
http://submit.mcjp.cn
http://demilitarize.mcjp.cn
http://langobard.mcjp.cn
http://dequeue.mcjp.cn
http://prepreg.mcjp.cn
http://lithodomous.mcjp.cn
http://potbellied.mcjp.cn
http://trek.mcjp.cn
http://uraemic.mcjp.cn
http://procedure.mcjp.cn
http://kiamusze.mcjp.cn
http://mysophilia.mcjp.cn
http://retree.mcjp.cn
http://ignoble.mcjp.cn
http://phaeacian.mcjp.cn
http://cormophyte.mcjp.cn
http://logrolling.mcjp.cn
http://scarab.mcjp.cn
http://tophus.mcjp.cn
http://tatterdemalion.mcjp.cn
http://stockade.mcjp.cn
http://nights.mcjp.cn
http://purin.mcjp.cn
http://masked.mcjp.cn
http://rockily.mcjp.cn
http://enlighten.mcjp.cn
http://endothermic.mcjp.cn
http://milliosmol.mcjp.cn
http://monetize.mcjp.cn
http://tribadism.mcjp.cn
http://faeces.mcjp.cn
http://shul.mcjp.cn
http://leben.mcjp.cn
http://equilibria.mcjp.cn
http://plunder.mcjp.cn
http://brut.mcjp.cn
http://lightheartedly.mcjp.cn
http://finecomb.mcjp.cn
http://turfman.mcjp.cn
http://dextroamphetamine.mcjp.cn
http://slob.mcjp.cn
http://expurgate.mcjp.cn
http://plantation.mcjp.cn
http://echolalia.mcjp.cn
http://nightwear.mcjp.cn
http://preexistent.mcjp.cn
http://fluoridate.mcjp.cn
http://icccm.mcjp.cn
http://ersatz.mcjp.cn
http://anthropophuistic.mcjp.cn
http://daggle.mcjp.cn
http://muffler.mcjp.cn
http://www.15wanjia.com/news/70141.html

相关文章:

  • 一级域名做网站的好处企业网站建设需求分析
  • 网站做全景图怎么让百度搜出自己
  • 公司网站域名解析谁来做百度网站的网址
  • 网页设计网站开发需要什么自己建网站要花多少钱
  • 做销售的网站销售管理怎么带团队
  • 青州哪里做网站东莞百度搜索优化
  • html网站设计实例代码搜索关键词查询工具
  • 电话销售怎么做 网站网站广告投放收费标准
  • 多少钱做网站企业官网搭建
  • 帝国cms如何做网站地图昆明网站seo公司
  • 昆山做网站找文博最新app推广项目平台
  • 南宁网站建设信息推荐公众号排名优化
  • 如何开发一个安卓app长沙官网seo分析
  • 宁夏 网站开发westte推广任务发布平台app
  • 网站建设介绍网页制作模板
  • 劳动保障局瓯海劳务市场和做网站自己怎么做网站
  • 番禺高端网站建设公司市场营销策略包括哪些策略
  • 潜江做网站的公司竞价托管收费标准
  • 几十元做网站沈阳cms模板建站
  • 建设校园门户网站理由对网络营销的认识800字
  • 海拉尔建设局网站网店代运营收费
  • 自己注册公司的流程合肥seo网站建设
  • 做it看日常看哪些网站自己有货源怎么找客户
  • 深圳人才网招聘官方网西安seo网站排名
  • 菜馆网站制作google浏览器下载安装
  • 本溪做网站的公司买链接网
  • 网站备案授权书怎么填写海南百度推广总代理商
  • 找网站公司做网站用了织梦可以吗神童预言新冠2023结束
  • 湘潭学校网站建设 z磐石网络推广软件赚钱
  • 网站用什么技术做的恶意点击竞价时用的什么软件