7.pytest测试完成后通过allure生成测试报告

本篇文章写的是通过allure生成测试报告,当然pytest有自己生成测试报告方式,官网网站也提供了报告优化的代码。但是相比起来还是allure的报告更能直观的显示;

1.allure环境搭建

安装python支持的allure第三方模块

pip install allure-pytest

安装allure命令行工具,后期用来启动服务

# github 中下载
https://github.com/allure-framework/allure2/releases

将下载的allure中的bin目录配置到环境变量

 2.编写用例,通过allure装饰器形式标记用例(详细的标记在下方)

import allure

@allure.feature('计算器模块')
class Test_login():

    @allure.story('第一个测试用例')
    def test_1(self):
        assert 1+2 == 3

    @allure.story('第二个测试用例')
    def test_2(self):
        assert 2-2 == 0

    @allure.story('第三个测试用例')
    def test_3(self):
        assert 3*3 == 9

    @allure.story('第四个测试用例')
    def test_4(self):
        assert 10/2 ==5

3.执行用例

# 指定报告存放路径
pytest test_5.py --alluredir ./report

测试结束后报告并非html格式

 启动allure服务,展示测试报告

allure serve report # report为上一步指定的报告路径,系统会自动分配端口

 4.allure详细标记用例格式

临时挂上官网描述,后期补充  https://docs.qameta.io/allure/#_pytest

 

 

 

 

 

 

posted @ 2020-02-06 13:05  不休不止  阅读(684)  评论(0编辑  收藏  举报