首页 > 技术文章 > python使用allure进行报告生成

chongyou 2020-04-06 22:01 原文

基础以及安装可以查看这两篇文章,我就直接上如何使用,不理解可以参考这两篇文章

https://blog.csdn.net/liuchunming033/article/details/79624474

https://blog.csdn.net/hh20161314/article/details/97292096

使用和效果

import pytest
import allure
class Test_all():
    @allure.step(title="allure通过注解方式完成内容的展示,setp表示测试步骤1...")
    def test_setup(self):
        print("我就是打酱油的setup")

    @allure.step(title="run就是一个正常的方法.")
    def test_run(self):
        allure.attach("自定义描述1", "描述内容,自定义")
        print("我要运行")
        assert True

    def test_skip(self):
        print("我要跳过")

    @allure.severity(allure.severity_level.BLOCKER)  #严重级别
    @allure.testcase("http://www.baidu.com/", "测试用例的地址")
    @allure.issue("http://music.migu.cn/v3/music/player/audio", "点击可跳转到bug地址")
    def test_error(self):
        with allure.attach("自定义描述1", "我需要让他进行错误"):
            print("我错误了")
            assert False

在控制台第一次运行方式,生成数据:pytest test_report.py   --alluredir report

在控制台第二次把数据生成报告:allure generate report/ -o report/html

生成报告文件

 

 

运行命令方式

使用cmd运行,或者使用pycharm运行都是可以的,以下我使用pycharm的环境运行

1.进入运行项目的目录下 执行命令 pytest 运行的py文件

 

 

2.上图有一个F就是表示有错误日志,执行完后,就会直接打印到了屏幕上

 

3.我们使用命令生成报告

 

 4.在我进入的目录中就可以看到生成了文件

推荐阅读