• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

pytest--allure报告添加用例详情

武飞扬头像
测试-安静
帮助1

前言

前面介绍了如何生成allure的报告,看着allure的页面非常好看,但是感觉少了一些内容,allure还可以增加一些用例详情内容,这样让我们的报告看着更加绚丽。

allure增加用例详情

我们可以在报告测试套件中增加用例详情内容。

用例标题

1、需要导入allure模块

2、在每条用例函数前需要加上 @allure.title('标题内容') 

3、正常执行生成allure报告。

  1.  
    import allure
  2.  
     
  3.  
    class TestCase:
  4.  
     
  5.  
    @allure.title('用例1的名称')
  6.  
    def test_01(self):
  7.  
    print('---用例01---')
  8.  
    assert 1
  9.  
     
  10.  
    @allure.title('用例2的名称')
  11.  
    def test_02(self):
  12.  
    print('---用例02---')
  13.  
    assert 1
  14.  
     
  15.  
    @allure.title('用例3的名称')
  16.  
    def test_03(self):
  17.  
    print('---用例03---')
  18.  
    assert 2

学新通

通过在cmd中输入 pytest --alluredir ./report/result 执行测试用例,在执行 allure serve report/result 打开allure报告。这样就能在报告中看出生成了三条用例,并将对应的用例名称显示出来了。

学新通

用例描述

用例除了用例标题显示出用例内容外,我们也可以通过用例描述更加详细的在allure中展示出来

这里和unittest的时候显示标题一样,直接通过python的语法在用例中增加注释

  1.  
    import allure
  2.  
     
  3.  
    class TestCase:
  4.  
     
  5.  
    @allure.title('用例1的名称')
  6.  
    def test_01(self):
  7.  
    '''用例_01的描述内容'''
  8.  
    print('---用例01---')
  9.  
    assert 1
  10.  
     
  11.  
    @allure.title('用例2的名称')
  12.  
    def test_02(self):
  13.  
    '''用例_02的描述内容'''
  14.  
    print('---用例02---')
  15.  
    assert 1
  16.  
     
  17.  
    @allure.title('用例3的名称')
  18.  
    def test_03(self):
  19.  
    '''用例_03的描述内容'''
  20.  
    print('---用例03---')
  21.  
    assert 2

学新通

同样通过cmd命令行中输入对应的打开allure的报告内容。可以进入到用例详情页面中查看到,描述已经成功添加了。

学新通

用例操作步骤

allure中也可以添加将用例的操作步骤进行添加进去,这里通过 allure.step() 的方法来实现添加操作步骤

  1.  
    import allure
  2.  
     
  3.  
    class TestCase:
  4.  
     
  5.  
    @allure.title('登录用户')
  6.  
    def test_01(self):
  7.  
    '''登录用户'''
  8.  
    print('---用例01---')
  9.  
    with allure.step('输入登录用户名'):
  10.  
    print('输入用户名')
  11.  
    with allure.step('输入登录的密码'):
  12.  
    print('输入密码')
  13.  
    with allure.step('点击登录'):
  14.  
    print('点击登录!')
  15.  
    assert 1
  16.  
     
  17.  
    @allure.title('进入测试页面')
  18.  
    def test_02(self):
  19.  
    '''进入测试页面'''
  20.  
    print('---用例02---')
  21.  
    with allure.step('进入测试页面'):
  22.  
    print('进入测试页面')
  23.  
    with allure.step('点击测试内容'):
  24.  
    print('点击测试内容')
  25.  
    assert 1

学新通

和上面的操作一样,打开cmd进行生成allure命令。通过在allure中进行查看报告内容。可以看到已经在测试步骤中添加上了。

 学新通

定义测试用例相关链接

自动化测试用例都是通过功能用例转换过来的,我们也可以通过allure将我们的测试用例相关的链接到我们的自动化测试用例中,并通过allure展示出来,这里可以通过 @allure.issue() 进行添加bug缺陷内容, @allure.testcase() 添加测试用例链接

  1.  
    import allure
  2.  
     
  3.  
    class TestCase:
  4.  
     
  5.  
    @allure.issue('https://home.cnblogs.com/u/qican/')
  6.  
    @allure.testcase('https://www.百度.com/')
  7.  
    @allure.title('登录用户')
  8.  
    def test_01(self):
  9.  
    '''登录用户'''
  10.  
    print('---用例01---')
  11.  
    with allure.step('输入登录用户名'):
  12.  
    print('输入用户名')
  13.  
    with allure.step('输入登录的密码'):
  14.  
    print('输入密码')
  15.  
    with allure.step('点击登录'):
  16.  
    print('点击登录!')
  17.  
    assert 1
  18.  
     
  19.  
    @allure.issue('https://home.cnblogs.com/u/qican/')
  20.  
    @allure.testcase('https://www.百度.com/')
  21.  
    @allure.title('进入测试页面')
  22.  
    def test_02(self):
  23.  
    '''进入测试页面'''
  24.  
    print('---用例02---')
  25.  
    with allure.step('进入测试页面'):
  26.  
    print('进入测试页面')
  27.  
    with allure.step('点击测试内容'):
  28.  
    print('点击测试内容')
  29.  
    assert 1

学新通

继续通过allure的报告执行方式,生成allure报告和打开allure报告,就可以看到我们的测试用例相关链接已经添加好了。

学新通

用例标签模块

功能测试中可以对测试用例根据不同的模块进行划分,自动化中也可以对用例进行不同模块的划分,然后通过allure的形式进行展示出来,这里我们可以通过 @allure.feature() 对其用例进行增加不同模块。也可以通过 @allure.epic 设置用例整体标签以及模块内容

  1.  
    import allure
  2.  
     
  3.  
    @allure.epic("属于登录标签")
  4.  
    @allure.feature('登录模块')
  5.  
    class TestCase:
  6.  
    @allure.title('登录用户')
  7.  
    def test_01(self):
  8.  
    '''登录用户'''
  9.  
    print('---用例01---')
  10.  
    with allure.step('输入登录用户名'):
  11.  
    print('输入用户名')
  12.  
    with allure.step('输入登录的密码'):
  13.  
    print('输入密码')
  14.  
    with allure.step('点击登录'):
  15.  
    print('点击登录!')
  16.  
    assert 1
  17.  
     
  18.  
    @allure.title('进入测试页面')
  19.  
    def test_02(self):
  20.  
    '''进入测试页面'''
  21.  
    print('---用例02---')
  22.  
    with allure.step('进入测试页面'):
  23.  
    print('进入测试页面')
  24.  
    with allure.step('点击测试内容'):
  25.  
    print('点击测试内容')
  26.  
    assert 1
  27.  
     
  28.  
    @allure.epic("属于退出登录标签")
  29.  
    @allure.feature('退出登录模块')
  30.  
    class Test01:
  31.  
     
  32.  
    def test_01(self):
  33.  
    print('---用例03---')
  34.  
     
  35.  
    def test_02(self):
  36.  
    print('---用例04---')

学新通

同样通过cmd进行生成allure报告,然后通过查看allure报告内容,通过下图已经可以很清楚的看出来在增加了用例标签和用例模块

学新通

总结

通过上面安静简单的总结,allure还是很强大的,可以将我们的报告设计的更加好看,对应测试用例模块的划分也很好的展示出来,最最最主要的是领导能看懂了。好了,感谢您的阅读,希望对您有所帮助

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /boutique/detail/tanhhgbbgh
系列文章
更多 icon
同类精品
更多 icon
继续加载