享受每一天,Just Enjoy !

0%

Python 自动化测试实战基础 Zero to Hero 测试报告Allure(三)

  • 自动化测试执行完毕后,需要测试报告来层现测试结果。有个‘像样’的报告的好处是毋庸置疑的,今天就来简单的讲述一下自动化测试后经常使用到的测试报告Allure

    本文首发于伊洛的个人博客:https://yiluotalk.com,欢迎关注并查看更多内容!!!

    1. 安装
  • Mac下安装直接homebrew
    1
    2
    3
    4
    #伊洛Yiluo 
    #https://www.yiluotalk.com

    brew install allure
  • 检查一下安装的结果
    1
    2
    3
    4
    #伊洛Yiluo 
    #https://www.yiluotalk.com
    ➜ ~ allure --version
    2.13.1
  • 以上说明已经成功安装
    2. 安装allure-pytest
1
2
3
#伊洛Yiluo 
#https://www.yiluotalk.com
pip install allure-pytest
3. 举个栗子
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 伊洛Yiluo
# https://www.yiluotalk.com
import pytest


def test_success():
assert True


def test_failure():
assert False


def test_skip():
pytest.skip('跳过测试')


def test_broken():
raise Exception('出错了')
  • 生成报告分2个步骤(后面是生成报告的路径)
    1
    2
    3
    # 伊洛Yiluo
    # https://www.yiluotalk.com
    pytest --alluredir=/tmp/my_allure_results
    1
    2
    3
    # 伊洛Yiluo
    # https://www.yiluotalk.com
    allure serve /tmp/my_allure_results
  • 实际尝试下查看结果
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # 伊洛Yiluo
    # https://www.yiluotalk.com
    E assert False

    test_sample.py:13: AssertionError
    ___________________________________ test_broken ___________________________________

    def test_broken():
    > raise Exception('出错了')
    E Exception: 出错了

    test_sample.py:21: Exception
    ===================== 2 failed, 1 passed, 1 skipped in 0.08s ======================
    1
    2
    3
    4
    5
    6
    7
    # 伊洛Yiluo
    # https://www.yiluotalk.com
    Generating report to temp directory...
    Report successfully generated to /var/folders/76/fkp3njt56f97wsxgpy94mjh00000gn/T/1826909724101378741/allure-report
    Starting web server...
    2019-12-24 14:34:54.474:INFO::main: Logging initialized @13022ms to org.eclipse.jetty.util.log.StdErrLog
    Server started at <>. Press <Ctrl+C> to exit
    4. 查看测试报告
  • 执行完上面的命令后会自动打开默认的浏览器显示测试报告
    在这里插入图片描述

欢迎下方【戳一下】【点赞】
Author:伊洛Yiluo
愿你享受每一天,Just Enjoy !

关注公众号获取更多内容