压铸东莞网站建设中国站长之家

news/2025/10/6 12:51:41/文章来源:
压铸东莞网站建设,中国站长之家,做棋牌推广网站违反不,wordpress woocommerce主题结合单元测试框架pytest数据驱动模型allure 目录 api#xff1a; 存储测试接口 conftest.py :设置前置操作 目前前置操作#xff1a;1、获取token并传入headers#xff0c;2、获取命令行参数给到环境变量,指定运行环境 commmon#xff1a;存储封装的公共方法 connect_mysq…结合单元测试框架pytest数据驱动模型allure 目录 api 存储测试接口 conftest.py :设置前置操作              目前前置操作1、获取token并传入headers2、获取命令行参数给到环境变量,指定运行环境 commmon存储封装的公共方法          connect_mysql.py连接数据库          http_requests.py: 封装自己的请求方法          logger.py: 封装输出日志文件          read_yaml.py读取yaml文件测试用例数据          read_save_data.py读取保存的数据文件 case: 存放所有的测试用例        data存放测试需要的数据       save_data: 存放接口返回数据、接口下载文件       test_data: 存放测试用例依赖数据       upload_data: 存放上传接口文件 logs: 存放输出的日志文件 report: 存放测试输出报告 getpathinfo.py :封装项目测试路径 pytest.int :配置文件 requirement.txt: 本地python包pip install -r requirements.txt 安装项目中所有python包 run_main.py: 项目运行文件 结构设计 1.每一个接口用例组合在一个测试类里面生成一个py文件 2.将每个用例调用的接口封装在一个测试类里面生成一个py文件 3.将测试数据存放在yml文件中通过parametrize进行参数化实现数据驱动 4.通过allure生成测试报告 代码展示 api/api_service.py #需要测试的一类接口 Code description:服务相关接口 Create time: 2020/12/3 Developer: 叶修import os from common.http_requests import HttpRequestsclass Api_Auth_Service(object):def __init__(self):self.headers HttpRequests().headersdef api_home_service_list(self):# 首页服务列表# url http://192.168.2.199:9092/v1/auth/auth_service/findAuthServiceurl os.environ[host] /v1/auth/auth_service/findAuthService # 读取conftest.py文件地址进行拼接response HttpRequests().get(url, headersself.headers, verifyFalse)# print(response.json())return responsedef get_service_id(self):#获取银行卡三要素认证服务idurl http://192.168.2.199:9092/v1/auth/auth_service/findAuthService#url os.environ[host] /v1/auth/auth_service/findAuthService # 读取conftest.py文件地址进行拼接response HttpRequests().get(url,headersself.headers)#print(response.json()[data][0][service_list][0][id])service_id response.json()[data][0][service_list][1][id]return service_iddef api_service_info(self,serviceId0b6cf45bec757afa7ee7209d30012ce1,developerId):#服务详情body {serviceId :serviceId,developerId:developerId}url http://192.168.2.199:9092/v1/auth/auth_service/findServiceDetail#url os.environ[host] /v1/auth/auth_service/findServiceDetail#读取conftest.py文件地址进行拼接response HttpRequests().get(url,headersself.headers,params body,verifyFalse)#print(response.json())return responsedef api_add_or_update_service(self,api_param_req,api_param_res,description,error_code,icon,id,interface_remarks,name,product_info,request_method,sample_code,sort,type,url):#服务添加或者更新body{api_param_req: api_param_req,api_param_res: api_param_res,description: description,error_code: error_code,icon: icon,id: id,interface_remarks: interface_remarks,name: name,product_info: product_info,request_method: request_method,sample_code: sample_code,sort: sort,type: type,url: url,}#url http://192.168.2.199:9092/v1/auth/auth_service/insertOrUpdateServiceurl os.environ[host] /v1/auth/auth_service/insertOrUpdateService # 读取conftest.py文件地址进行拼接response HttpRequests().post(url,jsonbody,headersself.headers,verifyFalse)return responsedef api_add_service_price(self,id,max_number,money,service_id,small_number):#服务价格添加body {id: id,max_number: max_number,money: money,service_id: service_id,small_number: small_number}# url http://192.168.2.199:9092/v1/auth/auth_service/insertServicePriceurl os.environ[host] /v1/auth/auth_service/insertServicePrice # 读取conftest.py文件地址进行拼接response HttpRequests().post(url, jsonbody, headersself.headers, verifyFalse)return responsedef api_apply_service(self,developer_id,service_id):#申请服务body {developer_id: developer_id,service_id: service_id}# url http://192.168.2.199:9092/v1/auth/auth_service/applyServiceurl os.environ[host] /v1/auth/auth_service/applyService # 读取conftest.py文件地址进行拼接response HttpRequests().post(url, jsonbody, headersself.headers, verifyFalse)return responseif __name__ __main__:#Auth_Service().api_home_service_list()Api_Auth_Service().get_service_id()#Auth_Service().api_service_info() api/get_token.py#获取登录token Code description获取token Create time2020-12-03 Developer叶修import osimport urllib3 from common.http_requests import HttpRequestsclass Get_Token(object):def get_token(self,account****,password****):#url http://192.168.2.199:9092/v1/auth/developer/accountLoginurl os.environ[host]/v1/auth/developer/accountLoginbody {account: account,password: password,}urllib3.disable_warnings()r HttpRequests().post(url, jsonbody,verifyFalse)#print(r.json())token r.json()[data][token]params {access_token: token}HttpRequests().params.update(params)#更新token到sessionreturn tokenif __name__ __main__:print(Get_Token().get_token()) case/test_service_info.py #上面接口某一测试用例 Code description: 服务详情 Create time: 2020/12/3 Developer: 叶修import sys import allure import pytest from common.logger import Log from common.read_yaml import ReadYaml from api.api_auth_service.api_auth_service import Api_Auth_Servicetestdata ReadYaml(auth_service.yml).get_yaml_data() # 读取数据allure.feature(服务详情) class Test_Service_Info(object):log Log()pytest.mark.processpytest.mark.parametrize(serviceId,developerId,expect, testdata[service_info],ids[服务详情])def test_service_info(self,serviceId,developerId,expect):self.log.info(%s{%s} % ((sys._getframe().f_code.co_name,------服务详情接口-----)))with allure.step(获取服务id):serviceId Api_Auth_Service().get_service_id()with allure.step(服务详情):msg Api_Auth_Service().api_service_info(serviceId,developerId)self.log.info(%s:%s % ((sys._getframe().f_code.co_name, 获取请求结果%s % msg.json())))# 断言assert msg.json()[result_message] expect[result_message]assert msg.json()[result_code] expect[result_code]assert url in msg.json()[data] conftest.py Code description:配置信息 Create time: 2020/12/3 Developer: 叶修import os import pytest from api.get_token import Get_Token from common.http_requests import HttpRequestspytest.fixture(scopesession) def get_token():前置操作获取token并传入headersGet_Token().get_token()if not HttpRequests().params.get(access_token, ):#没有get到token跳出用例pytest.skip(未获取token跳过用例)yield HttpRequests().reqHttpRequests().req.close()def pytest_addoption(parser):parser.addoption(--cmdhost, actionstore, defaulthttp://192.168.1.54:32099,helpmy option: type1 or type2) pytest.fixture(scopesession,autouseTrue) def host(request):获取命令行参数#获取命令行参数给到环境变量#pytest --cmdhost 运行指定环境os.environ[host] request.config.getoption(--cmdhost)print(当前用例运行测试环境:%s % os.environ[host]) common/connect_mysql.py Code description: 配置连接数据库 Create time: 2020/12/3 Developer: 叶修import pymysqldbinfo {host:******,user:root,password:******,port:31855 } class DbConnect():def __init__(self,db_conf,database):self.db_conf db_conf#打开数据库self.db pymysql.connect(database database,cursorclass pymysql.cursors.DictCursor,**db_conf)#使用cursor()方式获取操作游标self.cursor self.db.cursor()def select(self,sql):#sql查询self.cursor.execute(sql)#执行sqlresults self.cursor.fetchall()return resultsdef execute(self,sql):#sql 删除 提示 修改try:self.cursor.execute(sql)#执行sqlself.db.commit()#提交修改except:#发生错误时回滚self.db.rollback()def close(self):self.db.close()#关闭连接def select_sql(select_sql):查询数据库db DbConnect(dbinfo,databaseauth_platform)result db.select(select_sql)db.close()return resultdef execute_sql(sql):执行SQLdb DbConnect(dbinfo,databaseauth_platform)db.execute(sql)db.close()if __name__ __main__:sql SELECT * FROM auth_platform.auth_service where name四要素认证sel select_sql(sql)[0][name]print(sel) common/http_requests.py Code description: 封装自己的请求类型 Create time: 2020/12/3 Developer: 叶修 import requests# 定义一个HttpRequests的类 class HttpRequests(object):req requests.session()#定义session会话# 定义公共请求头headers {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36,cookie:}params {access_token:}# 封装自己的get请求,获取资源def get(self, url, params, data, headersNone, cookiesNone,streamNone,verifyNone):response self.req.get(url,paramsparams,datadata,headersheaders,cookiescookies,streamstream,verifyverify)return response# 封装自己的post方法创建资源def post(self, url, params,data, json, headersNone, cookiesNone,streamNone,verifyNone):response self.req.post(url,paramsparams,datadata,jsonjson,headersheaders,cookiescookies,streamstream,verifyverify)return response# 封装自己的put方法更新资源def put(self, url, params, data, headersNone, cookiesNone,verifyNone):response self.req.put(url, paramsparams, datadata, headersheaders, cookiescookies,verifyverify)return response# 封装自己的delete方法删除资源def delete(self, url, params, data, headersNone, cookiesNone,verifyNone):response self.req.delete(url, paramsparams, datadata, headersheaders, cookiescookies,verifyverify)return response common/logger.py Code description: 封装输出日志文件 Create time: 2020/12/3 Developer: 叶修import logging,time import os import getpathinfopath getpathinfo.get_path()#获取本地路径 log_path os.path.join(path,logs)# log_path是存放日志的路径 # 如果不存在这个logs文件夹就自动创建一个 if not os.path.exists(log_path):os.mkdir(log_path)class Log():def __init__(self):#文件的命名self.logname os.path.join(log_path,%s.log%time.strftime(%Y_%m_%d))self.logger logging.getLogger()self.logger.setLevel(logging.DEBUG)#日志输出格式self.formatter logging.Formatter(%(asctime)s - %(name)s - %(levelname)s - %(message)s)def __console(self,level,message):#创建一个fileHander用于写入本地fh logging.FileHandler(self.logname,a,encodingutf-8)fh.setLevel(logging.DEBUG)fh.setFormatter(self.formatter)self.logger.addHandler(fh)#创建一个StreamHandler,用于输入到控制台ch logging.StreamHandler()ch.setLevel(logging.DEBUG)ch.setFormatter(self.formatter)self.logger.addHandler(ch)if level info:self.logger.info(message)elif level debug:self.logger.debug(message)elif level warning:self.logger.warning(message)elif level error:self.logger.error(message)#避免日志重复self.logger.removeHandler(fh)self.logger.removeHandler(ch)#关闭打开文件fh.close()def debug(self,message):self.__console(debug,message)def info(self,message):self.__console(info,message)def warning(self,message):self.__console(warning,message)def error(self,message):self.__console(error,message)if __name__ __main__:log Log()log.info(测试)log.debug(测试)log.warning(测试)log.error(测试) common/read_save_data.py Code description: 读取保存数据 Create time: 2020/12/8 Developer: 叶修import os import yaml import getpathinfo class Read_Save_Date():def __init__(self):path getpathinfo.get_path()#获取本地路径self.head_img_path os.path.join(path,data,save_data)/head_img_path.txt# head_img_path文件地址self.order_id_path os.path.join(path, data, save_data) / order_id.txt # order_id.txt文件地址def get_head_img_path(self):# 获取head_img_pathwith open(self.head_img_path, r, encodingutf-8)as f:return f.read()def get_order_id(self):# 获取order_idwith open(self.order_id_path, r, encodingutf-8)as f:return f.read()if __name__ __main__:print(Read_Save_Date().get_head_img_path())print(Read_Save_Date().get_order_id()) common/read_yaml.py Code description: 读取yml文件测试数据 Create time: 2020/12/3 Developer: 叶修import os import yaml import getpathinfo class ReadYaml():def __init__(self,filename):path getpathinfo.get_path()#获取本地路径self.filepath os.path.join(path,data,test_data)/filename#拼接定位到data文件夹def get_yaml_data(self):with open(self.filepath, r, encodingutf-8)as f:# 调用load方法加载文件流return yaml.load(f,Loaderyaml.FullLoader)if __name__ __main__:data ReadYaml(auth_service.yml).get_yaml_data()[add_or_update_service]print(data) data/ data/test_data/auth_service.yml home_service_list:- [{result_code: 0, result_message: 处理成功}] service_info:- [,,{result_code: 0, result_message: 处理成功}] add_or_update_service:- [[1,1,1,1,1,123456,1,测试,1,1,1,1,1,1],{result_code: 0, result_message: 处理成功}] add_service_price:- [123456789,10,0,,0,{result_code: 0, result_message: 处理成功}] apply_service:- [,,{result_code: 0, result_message: 处理成功}] logs/ report/ getpathinfo.py Code description:配置文件路径 Create time: 2020/12/3 Developer: 叶修import osdef get_path():# 获取当前路径curpath os.path.dirname(os.path.realpath(__file__))return curpathif __name__ __main__:# 执行该文件测试下是否OKprint(测试路径是否OK,路径为, get_path()) pytest.ini #pytest.ini [pytest] markers process addopts -p no:warnings #addopts -v --reruns 1 --html./report/report.html --self-contained-html #addopts -v --reruns 1 --alluredir ./report/allure_raw #addopts -v -s -p no:warnings --reruns 1 --pytest_report ./report/Pytest_Report.html requirements.txt allure-pytest2.8.18 allure-python-commons2.8.18 BeautifulReport0.1.3 beautifulsoup44.9.3 ddt1.4.1 Faker4.18.0 Flask1.1.1 httpie1.0.3 httplib20.9.2 HttpRunner1.5.8 py1.9.0 PyMySQL0.10.1 pytest6.1.1 pytest-base-url1.4.2 pytest-cov2.10.1 pytest-forked1.3.0 pytest-html2.1.1 pytest-instafail0.4.2 pytest-metadata1.10.0 pytest-mock3.3.1 pywin32228 PyYAML5.3.1 requests2.22.0 requests-oauthlib1.3.0 requests-toolbelt0.9.1 run_main.py Code description: 运行主流程测试用例 Create time: 2020/11/5 Developer: 叶修import os import pytest if __name__ __main__:pytest.main([-m,process, -s,--alluredir, report/tmp])#-m运行mark标记文件os.system(allure generate report/tmp -o report/html --clean) # /report/tmp 为存放报告的源文件目录 感谢每一个认真阅读我文章的人礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走 这些资料对于【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴上万个测试工程师们走过最艰难的路程希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/929329.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

AtCoder Regular Contest 207 (Div.1) 游记

赛时一个半小时没出题,赛后再来三个小时终于搞出 A。省流 赛时一个半小时没出题,赛后再来三个小时终于搞出 A。10.5 内含剧透,请vp后再来。 不是题解!!!!!!! 赛前 本来发现要补的东西还剩很多,结果当天上午…

kubeadm续约k8s 1.23.14所有证书

[root@zy-nph-skg-fat-k8s-master01 kubernetes-1.23.14-0]# kubeadm certs renew all [renew] Reading configuration from the cluster... [renew] FYI: You can look at this config file with kubectl -n kube-sys…

Linux或者Windows下PHP版本查看便捷的方法总结

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

详细介绍:云原生时代 Kafka 深度实践:05性能调优与场景实战

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

深入解析:AI破局:饿了么如何搅动即时零售江湖

深入解析:AI破局:饿了么如何搅动即时零售江湖pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", &…

从零开始学Flink:数据输出的终极指南

本文详细介绍了Flink数据输出(Sink)的核心概念、各种连接器的使用方法、配置选项及可靠性保证机制。基于Flink 1.20.1的DataStream API,通过丰富的代码示例展示了如何将处理后的数据输出到Kafka、Elasticsearch、文件…

asp 企业网站dw制作一个手机网站模板下载地址

初识RPC RPC VS REST HTTP Dubbo Dubbo 特性: 基于接口动态代理的远程方法调用 Dubbo对开发者屏蔽了底层的调用细节,在实际代码中调用远程服务就像调用一个本地接口类一样方便。这个功能和Fegin很类似,但是Dubbo用起来比Fegin还要简单很多&a…

六盘水网站建设求职简历杭州公司网站建设套餐

FPGA-结合协议时序实现UART收发器(四):串口驱动模块uart_drive、例化uart_rx、uart_tx 串口驱动模块uart_drive、例化uart_rx、uart_tx,功能实现 文章目录 FPGA-结合协议时序实现UART收发器(四)&#xff1…

数据编织平台实现AI代理自助数据访问

数据管理初创公司发布即时数据编织平台重大更新,支持AI代理自助数据访问。平台采用自然语言处理与自动化数据准备技术,无需ETL流程即可跨数百个数据源提供统一访问,并配备上下文引擎和对话式AI助手。数据编织初创公…

高水平的锦州网站建设厦门网站设计大概多少钱

目录 一、简介 二、BeanFactory 三、FactoryBean 四、区别 五、使用场景 总结 一、简介 在Spring框架中,IOC(Inversion of Control)容器是一个核心组件,它负责管理和配置Java对象及其依赖关系,实现了控制反转&a…

广州设计公司网站磁县邯郸网站建设

是将若干个学习器(分类器&回归器)组合之后产生一个新学习器。弱分类器(weak learner)指那些分类准确率只稍微好于随机猜测的分类器(errorrate <。 集成算法的成功在于保证弱分类器的多样性(Diversity)。而且集成不稳定的算法也能够得到一个比较明显的性能提升。 常见的…

[题解]P12008 【MX-X10-T4】[LSOT-4] Fragment of Memories

P12008 【MX-X10-T4】[LSOT-4] Fragment of Memories 可以想到很 naive 的思路,对于每个 \(x\) 值二分答案 \(m\)。check 函数可以 \(O(n)\) 完成。总时间是 \(O(n^2\log n)\) 的。我们发现 check 函数明显还能凹,考…

自然语言处理(NLP)的系统学习路径规划 - 实践

自然语言处理(NLP)的系统学习路径规划 - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", &…

2.Android Compose 基础系列:在 Kotlin 中创建和使用变量

2.Android Compose 基础系列:在 Kotlin 中创建和使用变量在应用开发中,有些内容是固定的,例如“设置”中的菜单项;而有些内容会不断变化,比如新闻应用中的标题、来源或发布时间。为了让这些变化自动更新,而不是每…

wordpress开启多站点好处西安网站建设winkuo

shutil.copyfileobj() 是 Python 的 shutil 模块中用于复制文件对象内容的一个函数。它可以将一个文件对象的内容复制到另一个文件对象中。 shutil.copyfileobj(fsrc, fdst, length16*1024) fsrc: 源文件对象&#xff0c;即要从中复制内容的文件对象。fdst: 目标文件对象&…

线性表的顺序存储和链式存储

目录核心概念一、顺序存储(顺序表)1. 核心特点2. 实现方式3. 基本操作分析4. 优缺点总结二、链式存储(链表)1. 核心特点2. 实现方式(以单链表为例)3. 基本操作分析4. 优缺点总结三、对比总结表四、如何选择?核心…

AWS WebRTC:获取ICE服务地址(part 3):STUN服务和TURN服务的作用 - 实践

AWS WebRTC:获取ICE服务地址(part 3):STUN服务和TURN服务的作用 - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-famil…

完整教程:进阶配置与优化:配置 HTTPS 以确保数据安全传输

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

贵州省城乡和住房建设厅官方网站网络方案设计与实现

二、用go语言&#xff0c;给定一个n结点的二叉树&#xff0c;写出一个 O(n)时间的递归过程&#xff0c;将该树每个结点的关键字输出。 文心一言&#xff1a; 在Go语言中&#xff0c;你可以使用递归函数来遍历二叉树的所有节点&#xff0c;并输出每个节点的关键字。以下是一个…

Python中的对象池与驻留机制:小整数、字符串与大整数

Python中的对象池与驻留机制:小整数、字符串与大整数 Python为优化内存使用和执行效率,设计了多种对象复用机制,其中最典型的是小整数对象池、字符串驻留(intern)机制和大整数对象池。以下是整理后的详细说明,包…