Allure Test Report

对于不同的编程语言,有很多很酷的测试框架。不幸的是,它们中只有少数能够提供测试执行输出的良好表示。Qameta软件测试团队正在致力于Allure——一个开源框架,旨在创建测试执行报告,让团队中的每个人都清楚。

参考文章:

Allure官方文档:https://docs.qameta.io/allure/

https://blog.csdn.net/liuchunming033/article/details/79624474?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159587092119725247663810%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=159587092119725247663810&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v3~pc_rank_v3-1-79624474.pc_ecpm_v3_pc_rank_v3&utm_term=allure&spm=1018.2118.3001.4187

pytest与allure(/əˈlo͝or/)中间的火花

  1. 安装配置allure:https://github.com/allure-framework/allure2/releases/tag/2.13.5

    • 下载后解压文件并添加到对应操作系统的环境变量中
  2. 安装allure-pytest插件:pip install allure-pytest

  3. 添加allure测试结果报告存放路径pytest --alluredir=./report/allure_report_01(此方法会运行测试文件,并得到结果汇总到报告中,你还需执行下一步)

  4. 查看实际的报告(在浏览器显示,这样会在本地启用个web服务):allure serve ./report/allure_report_01

  5. 生成测试报告(每次生成前清空测试报告目录):allure generate ./report/allure_report_01/ -o ./report01/ --clean

  6. 注意事项

如果直接执行pytest --alluredir=report,将会直接在当前目录下新建一个report的目录,并会运行pytest测试;

定制allure报告

  1. 给allure报告中的测试方法添加描述: 只需要在测试函数/方法下加上"""描述的内容"""

    def test_sum(self):
    """ 这部分内容将显示在 allure报告中"""
    # assert进行断言
    assert 1 == 2
  2. 测试步骤描述:在测试方法之前添加@allure.step('步骤描述')内容

    #!/usr/bin/env/python3
    # -*- coding:utf-8 -*-
    """
    @project: pytest_study
    @author: zy7y
    @file: test_09.py
    @ide: PyCharm
    @time: 2020/7/27
    """ import allure
    import pytest @allure.step('第一步')
    def passing_step():
    pass @allure.step('第二步')
    def step_with_nested_steps():
    nested_step() @allure.step('第二.1步')
    def nested_step():
    nested_step_with_arguments(1, 'abc') @allure.step('第二.2步')
    def nested_step_with_arguments(arg1, arg2):
    pass def test_with_imported_step():
    passing_step() def test_with_nested_steps():
    passing_step()
    step_with_nested_steps()

    步骤可以有一个描述行,该描述行支持传递的位置参数和关键字参数的占位符。关键字参数的默认参数也将被捕获。

    import allure
    
    @allure.step('测试步骤标题中的占位符, 第一个参数: "{0}", 第二个参数keyword: "{key}"')
    def step_with_title_placeholders(arg1, key=None):
    pass def test_steps_with_placeholders():
    step_with_title_placeholders(1, key='something')
    step_with_title_placeholders(2)
    step_with_title_placeholders(3, 'anything')
  3. ids测试用例标题: 每条用例ids关键字参数的内容将被填充到allure报告中

    @pytest.mark.parametrize('username, password, expect',
    [('admin', '123456', '登录成功'),
    ('admin', '111111', '密码错误')], ids=["正常登录测试用例标题", "密码错误登录测试用例"])
    def test_login(username, password, expect):
    if username == 'admin' and password == '123456':
    assert expect == '登录成功'
    else:
    assert expect == '密码错误'

  4. 向allure某个测试用例/函数/方法中添加附件:arllure.attcah(body, name, attachment_type, extension)或者添加本地附件allure.attach.file(source, name, attachment_type, extension)

    1. body - 需要写入的文件内容
    2. name - 文件名称
    3. attachment_type - 文件类型 allure.attachment_type
    4. extension - 文件后缀名
    5. source - 文件所在路径
    import allure
    import pytest @pytest.fixture
    def attach_file_in_module_scope_fixture_with_finalizer(request):
    # 添加一个txt文件,文件名称为 file_name, 文件里面的内容为:allure文本附件内容
    allure.attach('allure文本附件内容', 'file_name', allure.attachment_type.TEXT) def test_multiple_attachments(attach_file_in_module_scope_fixture_with_finalizer):
    # 本地上传一个图片文件给allure,
    allure.attach.file('./Snipaste_2020-07-27_23-29-48.png', name='allure专用', attachment_type=allure.attachment_type.PNG)
    allure.attach('<head></head><body> a page </body>', 'html附件', allure.attachment_type.HTML)

  5. 定制测试标题(测试函数在allure中的显示方式)内容:@allure.title()

    @allure.title('测试标题:测试打开blog')
    @allure.step('3. 点击回车')
    def test_open_blog(browse_driver):
    browse_driver.find_element_by_id('su').click()
    #allure.dynamic.title('在成功完成测试后,标题被替换为这一行。')

  6. 添加链接:@allure.link或者@allure.issue或者@allure.testcase

    # 显示链接
    @allure.link('https://www.baidu.com/')
    def test_with_link():
    pass @allure.link('https://www.youtube.com/watch?v=Su5p2TqZxKU', name='allure.link 实现的,传递了一个url,一个name')
    def test_with_named_link():
    pass # 可以用来放禅道bug地址,它的图标是个虫子挺好的
    @allure.issue('https://www.baidu.com', '这就是显示图标,点击可以访问链接的 allure.issue')
    def test_with_issue_link():
    pass # 链接栏下方显示 测试用例标题, 点击实现跳转
    @allure.testcase(TEST_CASE_LINK, '测试用例标题')
    def test_with_testcase_link():
    pass

  7. 按标签分组执行:@allure.feature and @allure.story

    @allure.story('epic_1')
    def test_with_epic_1():
    pass @allure.story('story_1')
    def test_with_story_1():
    pass @allure.story('story_2')
    def test_with_story_2():
    pass @allure.feature('feature_2')
    @allure.story('story_2')
    def test_with_story_2_and_feature_2():
    pass # pytest test_09.py --allure-stories story_1,story_2 只执行 含这两个标签的 # pytest test_09.py --allure-features feature2 --allure-stories story2
  8. 按严重度(优先级)分组执行:@allure.severity

    # test.py
    import allure @allure.severity('blocker')
    def test_with_no_severity_label():
    pass @allure.severity(allure.severity_level.TRIVIAL)
    def test_with_trivial_severity():
    pass @allure.severity(allure.severity_level.NORMAL)
    def test_with_normal_severity():
    pass @allure.severity(allure.severity_level.NORMAL)
    class TestClassWithNormalSeverity(object): def test_inside_the_normal_severity_test_class(self):
    pass @allure.severity(allure.severity_level.CRITICAL)
    def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self):
    pass # 将执行严重性为NORML、CRITICAL的方法/类/函数
    # pytest tests.py --allure-severities normal,critical
    严重度(优先级)解释:
    BLOCKER = 'blocker' 系统阻断 对应bug优先级: 马上解决
    CRITICAL = 'critical' 严重缺陷 -
    NORMAL = 'normal' 普通 - 可倒数第三执行 正常处理
    MINOR = 'minor' 易用性问题
    TRIVIAL = 'trivial' 易用性问题

    关于bug严重度、优先级可以看这里:http://blog.sina.com.cn/s/blog_4adc4b090102wucf.html

Pytest单元测试框架-allure测试报告的更多相关文章

  1. Pytest单元测试框架:插件-allure-pytest环境搭建并在本地生成一个测试报告

    之前写了allure-pytest的官方文档啃的内容,有些交流的朋友,实践起来没什么头绪,所以就有了这篇文章,也给自己填个坑 第一步:搭建Allure.JDK环境 1. 搭建JDK环境 不装jdk你会 ...

  2. Pytest单元测试框架-测试用例运行规则

    1.Pytest测试用例运行规则 在pytest单元测试框架下面执行用例,需要满足以下几个特点: 1. 文件名以test_*.py开头或者*_test.py 2. 测试类.测试函数以test开头 3. ...

  3. Pytest单元测试框架-Pytest环境安装

    unittest是python自带的单元测试框架,它封装好了一些校验返回的结果方法和一些用例执行前的初始化操作,使得单元测试易于开展,因为它的易用性,很多同学也拿它来做功能测试和接口测试,只需简单开发 ...

  4. Pytest单元测试框架之简单操作示例

    前言: Pytest是第三方单元格测试框架,更加简单,灵活,而且提供了更多丰富的扩展: Pytest与UnitTest框架的区别 UnitTest测试用例执行顺序是依照ascii码执行,而Pytest ...

  5. Pytest单元测试框架——Pytest+Allure+Jenkins的应用

    一.简介 pytest+allure+jenkins进行接口测试.生成测试报告.结合jenkins进行集成. pytest是python的一种单元测试框架,与python自带的unittest测试框架 ...

  6. Pytest 单元测试框架

    1.pytest 是 python 的第三方单元测试框架,比自带 unittest 更简洁和高效 2.安装 pytest pip install pytest 3.验证 pytest 是否安装成功 p ...

  7. Pytest单元测试框架之FixTure基本使用

    前言: 在单元测试框架中,主要分为:测试固件,测试用例,测试套件,测试执行及测试报告: 测试固件不难理解,也就是我们在执行测试用例前需要做的动作和测试执行后的需要做的事情: 比如在UI自动化测试中,我 ...

  8. Pytest单元测试框架-学习

    pytest: Python的一个单元测试框架,基于UnitTest二次开发,语法上更加简洁,可以用来做Python开发项目的单元测试,UI自动化.接口自动化测试等,有很多的插件访问Pytest插件汇 ...

  9. Pytest单元测试框架生成HTML测试报告及优化

    一.安装插件 要生成html类型的报告,需要使用pytest-html插件,可以在IDE中安装,也可以在命令行中安装.插件安装 的位置涉及到不同项目的使用,这里不再详述,想了解的可自行查询. IDE中 ...

随机推荐

  1. 微信小程序中的深拷贝与浅拷贝问题

    最近在弄小程序项目的时候遇到了一个json对象复制的问题,也就是俗称的深拷贝与浅拷贝了. 一般用变量直接接收就是浅拷贝,那么如何理解浅拷贝与深拷贝的意义呢? 浅拷贝:只是将对象地址的复制,并没有开辟新 ...

  2. 数据可视化基础专题(十):Matplotlib 基础(二) 自定义配置文件和绘图风格(rcParams和style)

    https://matplotlib.org/api/rcsetup_api.html#module-matplotlib.rcsetup 一.什么是rcParams?我们在使用matplotlibl ...

  3. How to start MySQL on Linux

    启动MySQL数据库 service mysql start 查看MySQL进程 ps -ef |grep mysql 查看MySQL端口号 cd /etc/init.d/ netstat -atnp ...

  4. 基于svg的环形进度条

    其实需求是这么一个基于日期的环形进度条,开始用css3写了一下感觉太麻烦了,于是抽了点时间用svg画了一个. 不多说 上代码: css: <style> circle { -webkit- ...

  5. Spring配置类深度剖析-总结篇(手绘流程图,可白嫖)

    生命太短暂,不要去做一些根本没有人想要的东西.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习 ...

  6. 使用pycharm、跳板机连接内网服务器

    使用pycharm.跳板机连接内网服务器 接手实验室服务器后,大部分同学在GPU集群上跑程序都是直接在ssh界面上跑,这里想着通过pycharm通过跳板机来连接服务器. 总体就是实验室服务器仅限内网访 ...

  7. Ubuntu18.04安装Docker并部署(编译、发布、构建镜像)Asp.NetCore项目全过程笔记

      环境准备:阿里云Ubuntu18.04 全新安装   一.安装Docker 1.删除旧版本并更新包索引: sudo apt-get remove docker docker-engine dock ...

  8. Python 如何生成 200 个激活码

    请用 Python 如何生成 200 个激活码. 激活码的格式为asqE-9xRK-lqWU-QkMT 要求1: 使用随机生成时,生成数字概率为1/5,大写字母和小写字母概率各为2/5 要求2: 这2 ...

  9. mdk/iar汇编区别

    在代码移植中,经常遇到iar的代码转换问题,在此不间断记录一些,个人感觉还是IAR的更接近C一些,备查: 1. #ifdef的使用 // IAR #ifdef MACRO_XX #endif // M ...

  10. javascript原型:写一个合并后数组去掉同类项的方法

    <!DOCTYPE html> <html> <head> <title>test013_Array_prototype_unique()</ti ...