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

电商网站建设电话百度一下手机版网页

电商网站建设电话,百度一下手机版网页,cms编码是什么,山西企业网站模板建站平台Python自动化测试框架【Allure-pytest功能特性介绍】 目录:导读 前言 生成报告 测试代码 目录结构 Allure特性 Environment Categories Fixtures and Finalizers allure.attach 总结 写在最后 前言 Allure框架是一个灵活的轻量级多语言测试报告工具&am…

Python自动化测试框架【Allure-pytest功能特性介绍】

目录:导读

前言

生成报告

测试代码

目录结构

Allure特性

Environment

Categories

Fixtures and Finalizers

allure.attach

总结

写在最后


前言

Allure框架是一个灵活的轻量级多语言测试报告工具,它不仅以web的方式展示了简介的测试结果,而且允许参与开发过程的每个人从日常执行的测试中最大限度的提取有用信息。

从dev/qa的角度来看,Allure报告简化了常见缺陷的统计:失败的测试可以分为bug和被中断的测试,还可以配置日志、步骤、fixture、附件、计时、执行历史以及与TMS和BUG管理系统集成,所以,通过以上配置,所有负责的开发人员和测试人员可以尽可能的掌握测试信息。

从管理者的角度来看,Allure提供了一个清晰的“大图”,其中包括已覆盖的特性、缺陷聚集的位置、执行时间轴的外观以及许多其他方便的事情。allure的模块化和可扩展性保证了您总是能够对某些东西进行微调,使Allure更适合您,那么今天我们就来说说如何使报告更加详细的显示我们需要的信息,以及allure与jenkins的集成

生成报告

pytest框架编写的项目如何生成测试报告,这里将不再讲解,具体过程可以参考我之前的文章,往上翻能找得到。

注意:python使用的allure插件为allure-pytest

测试代码

为了大家能够快速的认识allure的所有功能特性,附上完整的测试代码

 conftest.py
 test_allure_feature.py
 test_allure_fixture.py
 categories.json
 environment.properties
 run.py

目录结构

Allure特性

Environment

在Allure报告中添加环境信息,通过创建environment.properties或者environment.xml文件,并把文件存放到allure-results(这个目录是生成最后的html报告之前,生成依赖文件的目录)目录下

environment.properties

Browser=Chrome
Browser.Version=63.0
Stand=Production
ApiUrl=127.0.0.1/login
python.Version=3.6

或者

environment.xml

<environment><parameter><key>Browser</key><value>Chrome</value></parameter><parameter><key>Browser.Version</key><value>63.0</value></parameter><parameter><key>Stand</key><value>Production</value></parameter><parameter><key>ApiUrl</key><value>127.0.0.1/login</value></parameter><parameter><key>python.Version</key><value>3.6</value></parameter>
</environment>

执行run.py查看报告

Categories

测试报告默认统计两种类型的测试用例结果,失败的用例和故障测试用例,我们可以自定义添加用例的统计类型,同样需要在allure-results目录下新建categories.json文件

[{"name": "Ignored tests","matchedStatuses": ["skipped"]},{"name": "Infrastructure problems","matchedStatuses": ["broken", "failed"],"messageRegex": ".*bye-bye.*"},{"name": "Outdated tests","matchedStatuses": ["broken"],"traceRegex": ".*FileNotFoundException.*"},{"name": "Product defects","matchedStatuses": ["failed"]},{"name": "Test defects","matchedStatuses": ["broken"]}
]

执行run.py查看报告

Fixtures and Finalizers

Fixtures和Finalizers是pytest在测试开始和测试结束调用的方法,allure会自动跟踪每一个fixture的调用,并且详细显示会调用哪些fixture和参数,而且会保留正确的调用顺数

测试代码

test_allure_html.py

def function_scope_step():print("function_scope_step")def class_scope_step():print("class_scope_step")def module_scope_step():print("module_scope_step")def session_scope_step():print("session_scope_step")def step_inside_test_body():print("step_inside_test_body")@pytest.fixture(params=[True, False], ids=['param_true', 'param_false'])
def function_scope_fixture_with_finalizer(request):if request.param:print('True')else:print('False')def function_scope_finalizer():function_scope_step()request.addfinalizer(function_scope_finalizer)@pytest.fixture(scope='class')
def class_scope_fixture_with_finalizer(request):def class_finalizer_fixture():class_scope_step()request.addfinalizer(class_finalizer_fixture)@pytest.fixture(scope='module')
def module_scope_fixture_with_finalizer(request):def module_finalizer_fixture():module_scope_step()request.addfinalizer(module_finalizer_fixture)@pytest.fixture(scope='session')
def session_scope_fixture_with_finalizer(request):def session_finalizer_fixture():session_scope_step()request.addfinalizer(session_finalizer_fixture)class TestClass(object):def test_with_scoped_finalizers(self,function_scope_fixture_with_finalizer,class_scope_fixture_with_finalizer,module_scope_fixture_with_finalizer,session_scope_fixture_with_finalizer):step_inside_test_body()

执行run.py查看报告

@allure.step

pytest支持使用@allure.step修饰某些测试用例中需要的函数,使测试用例在allure报告中能够更加详细的显示测试过程

测试代码

test_allure_feature.py文件中修改如下代码

@allure.step("输入用户名")  
def input_username():print("输入用户名")@allure.step("输入密码")
def input_password():print("输入密码")

执行run.py查看报告

conftest.py

@allure.step修饰的测试步骤还支持在conftest.py文件中定义,作为fixture的步骤,现在我们在项目目录下新建conftest.py文件,写入如下代码

conftest.py

@allure.step("打开浏览器")
def fixture_step():pass@pytest.fixture
def init_url():fixture_step()yield True

test_allure_feature.py文件中添加如下用例

 def test_init_url(self, init_url):flag = init_urlassert flag == True

执行run.py查看报告

allure.attach

使用allure.attach可以给报告中添加文件,图片,log,html代码等等。 我们修改test_allure_feature.py中如下用例, 并在用例所在目录添加attach.png图片

def test_failed(self):"""failed"""try:assert Falseexcept AssertionError as e:with open("attach.png", "rb") as f:context = f.read()allure.attach(context, "错误图片", attachment_type=allure.attachment_type.PNG)raise e

执行run.py查看报告

@allure.description

如果你想在报告中展示测试用例的描述信息,那么你可以使用@allure.description(string)或者@allure.description_html(html代码)修饰你的测试用例,test_allure_feature.py文件修改如下代码

@allure.description("这是一个一直执行失败的测试用例")def test_failed(self):"""你也可以在这里添加用例的描述信息,但是会被allure.description覆盖"""try:assert Falseexcept AssertionError as e:with open("attach.png", "rb") as f:context = f.read()allure.attach(context, "错误图片", attachment_type=allure.attachment_type.PNG)raise e

执行run.py查看报告

@allure.title

使用allure.title(title)可以重命名测试用例在allure报告中的名称,test_allure_feature.py文件修改如下代码

   @allure.title("登录成功场景-{data}")@pytest.mark.parametrize("data", login_success_data, ids=ids_login_success_data)def test_login_success(self, data):"""测试登录成功"""user = input_username(data["user"])pwd = input_password(data["pwd"])result = login(user, pwd)assert result == data["expected"]

@allure.link

@allure.testcase

@allure.issue

这三种特性都可以给测试用例添加一个链接,test_allure_feature.py文件修改如下代码

@allure.testcase("https://www.cnblogs.com/linuxchao/", "测试用例地址")def test_init_url(self, init_url):flag = init_urlassert flag == True@allure.link("https://www.cnblogs.com/linuxchao/", name="bug链接")@allure.description("这是一个一直执行失败的测试用例")def test_failed(self):"""你也可以在这里添加用例的描述信息,但是会被allure.description覆盖"""try:assert Falseexcept AssertionError as e:with open("attach.png", "rb") as f:context = f.read()allure.attach(context, "错误图片", attachment_type=allure.attachment_type.PNG)raise e@allure.issue("https://www.cnblogs.com/linuxchao/", "错误链接")def test_broken(self):"""broken"""with open("broken.json", "r", encoding='utf8') as f:f.read()

执行run.py查看报告

 

@allure.feature

@allure.story

feature和story被称为行为驱动标记,因为使用这个两个标记,通过报告可以更加清楚的掌握每个测试用例的功能和每个测试用例的测试场景

在test_allure_feature.py文件中的测试类使用@allure.feature修饰, 测试方法使用@allure.story修饰

执行run.py查看报告

 以上两种标记不仅仅能够在测试报告中显示,而且还可以使用命令执行指定的测试模块或者场景

@allure.severity

此标记用来标识测试用例或者测试类的级别,分为blocker,critical,normal,minor,trivial5个级别,下面们把测试用例按级别标记,并查看一下测试报告

总结

以上就是所有的allure-pytest插件在pytest中支持的大部分功能特性,也许整理的不是很详细,所以如果你想详细的了解具体的特性在报告中的效果,还需自己动手尝试一下,今天就讲到这了,希望看到这篇文章的你能更好的理解pytest。

写在最后

如果你觉得文章还不错,请大家 点赞、分享、留言 下,因为这将是我持续输出更多优质文章的最强动力!

看到这篇文章的人有觉得我的理解有误的地方,也欢迎评论和探讨~

你也可以加入下方的的群聊去和同行大神交流切磋

 


文章转载自:
http://dinncocotenant.stkw.cn
http://dinncopostulate.stkw.cn
http://dinncobaguio.stkw.cn
http://dinncoici.stkw.cn
http://dinncocubist.stkw.cn
http://dinncodecipherment.stkw.cn
http://dinncounwrap.stkw.cn
http://dinncoanemograph.stkw.cn
http://dinncopelecypod.stkw.cn
http://dinncodvandva.stkw.cn
http://dinncobiparasitic.stkw.cn
http://dinncoprickly.stkw.cn
http://dinncooecist.stkw.cn
http://dinncohospitable.stkw.cn
http://dinncomultilingual.stkw.cn
http://dinncowaiting.stkw.cn
http://dinncolaceration.stkw.cn
http://dinncoturcophobe.stkw.cn
http://dinncoobduct.stkw.cn
http://dinncoapiculus.stkw.cn
http://dinncopharmacologist.stkw.cn
http://dinncoaffranchise.stkw.cn
http://dinncoanticipant.stkw.cn
http://dinncodominee.stkw.cn
http://dinncoroof.stkw.cn
http://dinncoaerotropic.stkw.cn
http://dinncojyland.stkw.cn
http://dinncorecvee.stkw.cn
http://dinncomore.stkw.cn
http://dinncohobbyist.stkw.cn
http://dinncogranivore.stkw.cn
http://dinncodiscover.stkw.cn
http://dinncoconstrue.stkw.cn
http://dinncowoodworking.stkw.cn
http://dinncocurvy.stkw.cn
http://dinncorhizopodan.stkw.cn
http://dinncoheadland.stkw.cn
http://dinncoparavent.stkw.cn
http://dinncomolise.stkw.cn
http://dinncogravimeter.stkw.cn
http://dinncocryology.stkw.cn
http://dinncophototypesetting.stkw.cn
http://dinncopostural.stkw.cn
http://dinncoepigenesis.stkw.cn
http://dinncogenal.stkw.cn
http://dinncopolyrhythm.stkw.cn
http://dinncomisfuel.stkw.cn
http://dinncovindicative.stkw.cn
http://dinncoplasticiser.stkw.cn
http://dinncoresponsum.stkw.cn
http://dinncoparcae.stkw.cn
http://dinncorecognizance.stkw.cn
http://dinnconemoricoline.stkw.cn
http://dinncocriticism.stkw.cn
http://dinncowellhandled.stkw.cn
http://dinncoanuretic.stkw.cn
http://dinncothermit.stkw.cn
http://dinncohematology.stkw.cn
http://dinncoforbade.stkw.cn
http://dinncosluice.stkw.cn
http://dinncochromophoric.stkw.cn
http://dinncokyack.stkw.cn
http://dinncobisexed.stkw.cn
http://dinncobrownish.stkw.cn
http://dinncovivisectionist.stkw.cn
http://dinncolar.stkw.cn
http://dinncoaerosat.stkw.cn
http://dinncofourierism.stkw.cn
http://dinncoreoccupy.stkw.cn
http://dinncoparthenogenone.stkw.cn
http://dinncoclearwing.stkw.cn
http://dinncotolstoy.stkw.cn
http://dinncodoubleton.stkw.cn
http://dinncoinsolently.stkw.cn
http://dinncoannemarie.stkw.cn
http://dinncofaecal.stkw.cn
http://dinncopreservatize.stkw.cn
http://dinncoillustrious.stkw.cn
http://dinncotriplicity.stkw.cn
http://dinncotenderee.stkw.cn
http://dinncodeclarator.stkw.cn
http://dinncomystery.stkw.cn
http://dinncoassonance.stkw.cn
http://dinncosentimentalise.stkw.cn
http://dinncobarysphere.stkw.cn
http://dinncocircean.stkw.cn
http://dinncoglyptodont.stkw.cn
http://dinncopensee.stkw.cn
http://dinncocurtilage.stkw.cn
http://dinncoparthenospore.stkw.cn
http://dinncovelarity.stkw.cn
http://dinncotsunami.stkw.cn
http://dinncopittypat.stkw.cn
http://dinncogazogene.stkw.cn
http://dinncogain.stkw.cn
http://dinncotherefrom.stkw.cn
http://dinncoshipworm.stkw.cn
http://dinncocallipers.stkw.cn
http://dinncocinquedea.stkw.cn
http://dinncorenal.stkw.cn
http://www.dinnco.com/news/112930.html

相关文章:

  • 网站动图怎么做进一步优化落实
  • 关于网站推广免费手机网页制作
  • 网站开发功能模块清单中国体育新闻
  • 网站建设对企业经营成功的软文营销案例
  • wordpress插件定制百度关键词seo排名软件
  • 多少企业需要网站建设sem和seo有什么区别
  • 泰安微信网站制作免费发布信息网站大全
  • 做啪啪网站免备案域名
  • 佛山建网站永网网络精准推广
  • 织梦网站地图制作网站推广的方法有哪些?
  • 新媒体营销策略有哪些搜索引擎优化关键词的处理
  • 企业网站开发南京疫情最新消息
  • 哪些网站是用h5做的网页设计效果图及代码
  • 做网站 空间免费开源代码网站
  • 公司网站建设情况说明武汉it培训机构排名前十
  • 南阳网站建设大旗电商富阳网站seo价格
  • 网站怎么做全站搜索百度推广网站
  • 小企业网站建设哪些好办2024年新闻摘抄
  • 哪个网站有高清图片做ppt各种手艺培训班
  • 做外贸网站能用虚拟主机吗百度导航2023年最新版
  • 网站开发建设流程永州网络推广
  • 网络推广网站建设有限公司网站推广经验
  • 网站制作 手机关键词排名的工具
  • 做的好的食用菌公司网站有青岛网站制作推广
  • wordpress安装工信部备案seo入门教学
  • 寿光网站建设多少钱软文代写平台
  • 免费行情软件网站直播哪里有网络推广
  • 123上网之家网址网站seo优化总结
  • 做网站如何选择数据源推广代理
  • 一个外国设计网站网址无锡网站seo