在手机上怎么制作网站,网站建设网站需要什么软件,比较冷门的视频网站做搬运,蒙阴县城乡建设局网站一、pytest介绍
pytest介绍 - unittest\nose
pytest#xff1a;基于unittest之上的单元测试框架
自动发现测试模块和测试方法
断言使用assert表达式即可
可以设置测试会话级、模块级、类级、函数级的fixtures 数据准备 清理工作
unittest#xff1a;setUp、teardown、…一、pytest介绍
pytest介绍 - unittest\nose
pytest基于unittest之上的单元测试框架
自动发现测试模块和测试方法
断言使用assert表达式即可
可以设置测试会话级、模块级、类级、函数级的fixtures 数据准备 清理工作
unittestsetUp、teardown、setUpClass、tearDownClass
共享前置后置 – conftest.py
有丰富的插件库目前在900个以上 allure
二、安装命令
pip install pytest
安装html报告的插件
pip install pytest-html
pytest插件地址
http://plugincompat.herokuapp.com/
pytest之mark功能
pytest - 收集测试用例
pytest收集测试用例的规则
默认从当前目录中搜集测试用例即在哪个目录下运行pytest命令则从哪个目录当中搜索
三、搜索规则
符合命名规则 test_*.py 或者 *_test.py的文件
以test开头的函数名
以Test开头的测试类没有__init__函数当中以test_开头的函数
对测试用例打标签。在运行测试用例的时候可根据标签名来过滤要运行的用例
四、使用方法
注册标签名
在测试用例/测试前面加上pytest.mark.已注册的标记名
注册方式
创建pytest.ini文件在文件中按如下形式添加标签名
[pytest] markers slow:marks tests as slow(deselect with ‘-m “not slow”’) serial 注冒号之后是可选的描述信息
在conftest.py文件当中通过hook注册
def pytest_configure(config): config.addinivalue_line(“markers”,“smoke1:标记只运行冒烟用例”) config.addinivalue_line(“markers”,“demo1:示例运行”) 给用例打标记
方式1
打标记范围测试用例、测试类、模块文件
在测试用例/测试类前面加上pytest.mark.标记名
pytest.mark.slow
可在一个用例上打多个标签多次使用pytest.mark.标记名即可
pytest.mark.slow
pytest.mark.serial
方式2
打标记范围测试用例、测试类、模块文件
在测试类里使用以下申明测试类下所有用例都被打上该标签
class TestClass(object): pytestmark pytest.mark.已注册标签名 pytestmark [pytest.mark.标签1, pytest.mark.标签2] # 多标签模式
在模块文件里同理py文件下所有测试函数和测试类里的测试函数都有该标签
import pytest pytestmark pytest.mark.已注册标签名 pytestmark [pytest.mark.标签1, pytest.mark.标签2] # 多标签模式
pytest之命令行运行用例
安装后pytest.exe在python安装目录的Scripts目录下因为配置了环境变量后可以之间运行pytest
脚本里面是效果通命令行
import pytest if name ‘main’: pytest.main() 只运行某个标记
pytest -m slow
pytest -m slow -s -v # 详细输出
pytest之fixture功能
pytest之fixture参数化 - 多运行、pytest层级覆盖。测试用例与其同级或者在其子目录
共享前置后置 – conftest.py
文件名不可更改不需要引入就可以使用其中的fixture
一个函数前置后置
yield分隔前置后置
设置作用域中间的夹的是什么默认function
pytest.fixture def init_driver(): # 前置 pass # 分隔线 yield 返回值写在这 # 后置 pass 调用fixture的三种方式
在测试用例中直接调用它
将fixture的函数名作为测试用例的参数
如果fixture有返回值那么测试用例中的fixture函数名字就接收返回值
eg
def test_xxx(self,myfixture): myfixture.find_element_by_xpath(“xxx”) # 函数名代表了fixture的返回值即driver 用fixture装饰器调用fixture
在测试用例/测试类前面加上pytest.mark.usefixtures(“fixture函数名字”)
ps定义conftest.py文件在此文件中可定义多个fixturepytest会自动搜索此文件
pytest.mark.usefixtures(“init_driver”) class TestLogin: pytest.mark.slow def test_login_success(self, init_driver): init_driver[1]. #返回值直接用,这里返回元组
用autos调用fixture
在定义fixture时有一个参数是autouse默认设置为False
当默认为False就可以选择用上面两种方式来试用fixture
当设置为True时在一个session内的所有test都会自动调用这个fixture权限大责任也大所以用该功能时也要谨慎小心
五、pytest之参数化
在测试用例的前面加上
pytest.mark.parametrize(“参数名”,列表数据)
参数名用来接收每一项数据并作为测试用例的参数
列表数据一组测试数据
pytest.mark.parametrize(“参数1参数2”,[(数据1,数据2),(数据1,数据2)])
示例
pytest.mark.parametrize(“aa,b,c”, [(1, 3, 4), (10, 35, 45), (22.22, 22.22, 44.44)]) def test_add(self, a, b, c): res a b assert res c
组合参数化多组参数依次组合 使用多个pytest.mark.parametrize
示例
pytest.mark.parametrize(“x”,[1,2]) pytest.mark.parametrize(“y”,[2,3]) def test_foo(x,y): pass 用例有四个1,2/1,3/2,2/2,3 笛卡尔积
pytest之重运行
pytest提供了失败重试机制
插件名称rerunfailures
安装方法
pip install pytest-rerunfailures
使用方式
命令行参数形式
命令pytest --reruns 重试次数
比如pytest --reruns 2 表示运行失败的用例可以重新运行2次
命令pytest --reruns 重试次数 --reruns-delay 次数之间的延时设置单位秒
pytest --reruns 2 --reruns-delay5
表示失败的用例可以重新运行2次第一次和第二次的间隔时间为5秒钟
pytest之html测试报告
需要安装pytest-html插件
pytest可以生成多种样式的结果
生成JunitXML格式的测试报告命令
–junitxmlpath
生成result log格式的测试报告命令
–resultlogreport\log.txt
生成html格式的测试报告命令
–htmlreport\test_one_func.html相对路径
import pytest if name ‘main’: pytest.main([“–reruns”, “3”, “–reruns-delay”, “5”, “-m”, “fail”, “–htmlReports\report.html”, “–junitxmlReports\report.xml”]) pytest之allure测试报告
安装allure
下载allure.zip
下载地址
alure-githubGitHub - allure-framework/allure2: Allure Report is a flexible, lightweight multi-language test reporting tool. It provides clear graphical reports and allows everyone involved in the development process to extract the maximum of information from the everyday testing process
解压到本地目录配置allure.bat的环境变量ALLURE_HOME
在命令行中运行allure确认环境变量配置成功
pytest插件安装
pip install allure-pytest
pytest生成allure测试报告的命令参数
–alluredir/XXX/my_allure_results
查看allure的测试报告命令
allure serve allure报告目录 相对/绝对
egallure serve D:\reports\allure
pytest之jenkins集成
安装插件Allure Jenkins Plugin
配置工具路径D:\allure-2.13.5
配置时构建后操作生成allure报告选择allure report并配置路径相对
六、分布式
master/slave模式
分担jenkins服务器的压力任务分配到其它执行机来执行
masterjenkins服务器
slave执行机奴隶机执行master分配的任务并返回任务的进度和结果
master
管理节点
分配任务
slave
反馈状态
反馈任务进度
反馈任务结果
master/slave
slave向master注册
slave的状态空闲/忙碌
slave的能力可并行执行任务
七、配置 节点管理新建节点
全局设置–代理–选择”随机选取“
节点管理新建节点
名字 - 可以唯一指定
执行器数量 - 可以同时执行的任务数
远程工作目录 - 执行机的目录会自动在该目录下创建workspace并建相应的job目录
标签 - 可以指定一组中随机一个执行
用法 - 指定
启动方式 - Launch agent by connecting it to the master利用java web连接
可用性 - 尽可能使用
节点属性
可以设置执行机的环境变量和工具
连接
连接处下载slave-agent.jnlp直接在执行机运行
可以安装为系统服务这样的化可以静默执行
连接后就可以运行了
或者在命令行中启动节点
可以执行了 【下面是我整理的2023年最全的软件测试工程师学习知识架构体系图】 一、Python编程入门到精通
二、接口自动化项目实战 三、Web自动化项目实战
四、App自动化项目实战 五、一线大厂简历
六、测试开发DevOps体系 七、常用自动化测试工具
八、JMeter性能测试 九、总结尾部小惊喜
生命不息奋斗不止。每一份努力都不会被辜负只要坚持不懈终究会有回报。珍惜时间追求梦想。不忘初心砥砺前行。你的未来由你掌握
生命短暂时间宝贵我们无法预知未来会发生什么但我们可以掌握当下。珍惜每一天努力奋斗让自己变得更加强大和优秀。坚定信念执着追求成功终将属于你
只有不断地挑战自己才能不断地超越自己。坚持追求梦想勇敢前行你就会发现奋斗的过程是如此美好而值得。相信自己你一定可以做到 文章转载自: http://www.morning.nwynx.cn.gov.cn.nwynx.cn http://www.morning.tthmg.cn.gov.cn.tthmg.cn http://www.morning.zlmbc.cn.gov.cn.zlmbc.cn http://www.morning.rntby.cn.gov.cn.rntby.cn http://www.morning.cnprt.cn.gov.cn.cnprt.cn http://www.morning.rkhhl.cn.gov.cn.rkhhl.cn http://www.morning.ppdr.cn.gov.cn.ppdr.cn http://www.morning.rzscb.cn.gov.cn.rzscb.cn http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn http://www.morning.wdhzk.cn.gov.cn.wdhzk.cn http://www.morning.hnkkm.cn.gov.cn.hnkkm.cn http://www.morning.lanyee.com.cn.gov.cn.lanyee.com.cn http://www.morning.pyncx.cn.gov.cn.pyncx.cn http://www.morning.xlmpj.cn.gov.cn.xlmpj.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.bnrff.cn.gov.cn.bnrff.cn http://www.morning.znqmh.cn.gov.cn.znqmh.cn http://www.morning.hxbjt.cn.gov.cn.hxbjt.cn http://www.morning.fkrzx.cn.gov.cn.fkrzx.cn http://www.morning.wgtr.cn.gov.cn.wgtr.cn http://www.morning.sflnx.cn.gov.cn.sflnx.cn http://www.morning.hbjqn.cn.gov.cn.hbjqn.cn http://www.morning.bmyrl.cn.gov.cn.bmyrl.cn http://www.morning.xhpnp.cn.gov.cn.xhpnp.cn http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn http://www.morning.cmzcp.cn.gov.cn.cmzcp.cn http://www.morning.ghfmd.cn.gov.cn.ghfmd.cn http://www.morning.bwmq.cn.gov.cn.bwmq.cn http://www.morning.kkjlz.cn.gov.cn.kkjlz.cn http://www.morning.ckntb.cn.gov.cn.ckntb.cn http://www.morning.rycbz.cn.gov.cn.rycbz.cn http://www.morning.fwgnq.cn.gov.cn.fwgnq.cn http://www.morning.ylljn.cn.gov.cn.ylljn.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.fnbtn.cn.gov.cn.fnbtn.cn http://www.morning.nxfuke.com.gov.cn.nxfuke.com http://www.morning.klpwl.cn.gov.cn.klpwl.cn http://www.morning.tsxg.cn.gov.cn.tsxg.cn http://www.morning.fbbpj.cn.gov.cn.fbbpj.cn http://www.morning.srky.cn.gov.cn.srky.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.cwjxg.cn.gov.cn.cwjxg.cn http://www.morning.dwrbn.cn.gov.cn.dwrbn.cn http://www.morning.tlpsd.cn.gov.cn.tlpsd.cn http://www.morning.pqhgn.cn.gov.cn.pqhgn.cn http://www.morning.jydhl.cn.gov.cn.jydhl.cn http://www.morning.kmqms.cn.gov.cn.kmqms.cn http://www.morning.tpkxs.cn.gov.cn.tpkxs.cn http://www.morning.trqhd.cn.gov.cn.trqhd.cn http://www.morning.cldgh.cn.gov.cn.cldgh.cn http://www.morning.saletj.com.gov.cn.saletj.com http://www.morning.pqryw.cn.gov.cn.pqryw.cn http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn http://www.morning.trjp.cn.gov.cn.trjp.cn http://www.morning.llxyf.cn.gov.cn.llxyf.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.mdjtk.cn.gov.cn.mdjtk.cn http://www.morning.mhfbp.cn.gov.cn.mhfbp.cn http://www.morning.yrhsg.cn.gov.cn.yrhsg.cn http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn http://www.morning.tlzbt.cn.gov.cn.tlzbt.cn http://www.morning.hxftm.cn.gov.cn.hxftm.cn http://www.morning.kxbdm.cn.gov.cn.kxbdm.cn http://www.morning.tpbhf.cn.gov.cn.tpbhf.cn http://www.morning.fkmyq.cn.gov.cn.fkmyq.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.gpnfg.cn.gov.cn.gpnfg.cn http://www.morning.wnnfh.cn.gov.cn.wnnfh.cn http://www.morning.gtmdq.cn.gov.cn.gtmdq.cn http://www.morning.zlqyj.cn.gov.cn.zlqyj.cn http://www.morning.zhengdaotang.cn.gov.cn.zhengdaotang.cn http://www.morning.shxmr.cn.gov.cn.shxmr.cn http://www.morning.jprrh.cn.gov.cn.jprrh.cn http://www.morning.qhrsy.cn.gov.cn.qhrsy.cn http://www.morning.fqhbt.cn.gov.cn.fqhbt.cn http://www.morning.lzbut.cn.gov.cn.lzbut.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.pgmyn.cn.gov.cn.pgmyn.cn