石油大学 网页设计与网站建设,哪里有免费的网站自己做,如何用flashfxp上传网站,广州做公司网站的公司有哪些一、前提准备 1、前提#xff1a;需要安装pytest和pytest-html(生成html测试报告#xff09;
pip install pytest 和 pip install pytest-html
安装插件#xff1a;pip install 插件名
2、命名规范 Pytest单元测试中的类名和方法名必须是以test开头,执行中只能找到test开…一、前提准备 1、前提需要安装pytest和pytest-html(生成html测试报告
pip install pytest 和 pip install pytest-html
安装插件pip install 插件名
2、命名规范 Pytest单元测试中的类名和方法名必须是以test开头,执行中只能找到test开头的类和方法比unittest更加严谨
Pytest: setup, setup_class 和 teardown, teardown_class 函数 ( 和 unittest 执行效果一样 ) 运行于测试方法的始末即 : 运行一次测试函数会运行一次 setup 和 teardown 运行于测试方法的始末 , 但是不管有多少测试函数都只执行一次 setup_class 和 teardown_class 二、pytest生成自带的html测试报告 前提条件需要下载pytest-html模块(python自带的生成测试报告模块)
pip install pytest-html
如果不安装pytest-html会报
案例 1
pytest.main(模块.py)【运行指定模块下运行所有test开头的类和测试用例】 pytest.main([--html./report.html,模块.py])
import pytestclass Test():def test1(self):print(这是测试1)def test1(self):print(这是测试2)if __name__ __main__:pytest.main([--html./report.html, test_004.py])结果 2运行指定模块指定类指定用例冒号分割并生成测试报告
pytest.main([‘--html./report.html,‘模块.py::类::test_a_001])
import pytestclass Test():def test1(self):print(这是测试1)def test2(self):print(这是测试2)if __name__ __main__:pytest.main([--html./report.html, test_004.py::Test::test1])结果 3直接执行pytest.main() 【自动查找当前目录下以test 开头的文件或者以test结尾的py文件】
pytest.main([‘--html./report.html])
语句 pytst.main([-x,--html./report.html,t12est000.py])
-x出现一条测试用例失败就退出测试 -s:显示print内容 三、pytest运行方式 . 点号表示用例通过 F 表示失败 Failure E 表示用例中存在异常 Error 四、allure Allure是一款轻量级并且非常灵活的开源测试报告框架。 它支持绝大多数测试框架 例如TestNG、Pytest、JUint等。它简单易用易于集成
1、Allure常用的几个特性
allure.feature # 用于描述被测试产品需求
allure.story # 用于描述 feature 的用户场景即测试需求
with allure.step # 用于描述测试步骤将会输出到报告中
allure.attach # 用于向测试报告中输入一些附加的信息通常是一些测试数据截图等
案例1关于pytest与Allure生成html测试用例 rr.csv 2,3,5 5,6,11 readCsv
import csv # 导入csv模块class ReadCsv():def read_csv(self):item [] # 定义一个空列表c csv.reader(open(../dataDemo/rr.csv, r)) # 得到csv文件对象for csv_i in c:item.append(csv_i) # 将获取的数据添加到列表中return itemr ReadCsv()print(r.read_csv())开发代码
class Cale():def jia(self,a,b):cabreturn cdef jian(self,a,b):ca-breturn cdef cheng(self,a,b):ca*breturn cdef chu(self,a,b):ca/breturn c生成html代码
import pytestfrom pytest01.readDemo.readCsv import ReadCsvfrom pytest01.demo.cale import Caleimport osimport allurerReadCsv()ccr.read_csv()dCale()class Test():allure.story(加法函数测试正确)def test001(self):for i in cc:ddd.jia(int(i[0]),int(i[1]))assert ddint(i[2])if __name__ __main__:pytest.main([--alluredir, report/result, test_02.py])split allure generate ./report/result -o ./report/html --cleanos.system(split)总结
感谢每一个认真阅读我文章的人
作为一位过来人也是希望大家少走一些弯路如果你不想再体验一次学习时找不到资料没人解答问题坚持几天便放弃的感受的话在这里我给大家分享一些自动化测试的学习资源希望能给你前进的路上带来帮助。 软件测试面试文档
我们学习必然是为了找到高薪的工作下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料并且有字节大佬给出了权威的解答刷完这一套面试资料相信大家都能找到满意的工作。 视频文档获取方式 这份文档和视频资料对于想从事【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴我走过了最艰难的路程希望也能帮助到你以上均可以分享点下方小卡片即可自行领取。