allure插件安装

Allure是一个独立的报告插件,生成美观易读的报告。

目前支持语言:Java, PHP, Ruby, Python, Scala, C#。

Allure工具安装

https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/

添加 安装路径\allure-2.13.2\bin至环境变量PATH
完成以上步骤之后,命令行测试一下是否安装成功 :allure --version

 

allure-pytest安装

为了解决安装allure后执行命令后报错module 'pytest' has no attribute 'allure'的问题,发现之前安装了pytest-allure-adaptor

如果存在安装过的pytest-allure-adaptor插件,先卸载:pip uninstall pytest-allure-adaptor

重新安装allure-pytest:pip install allure-pytest

如果上述方法安装不了,则改用豆瓣进行安装,格式为:pip install 库名 -i http://pypi.douban.com/simple/  --trusted-host pypi.douban.com

 

Allure帮助文档: https://docs.qameta.io/allure/#_about

生成Allure报告: 命令行参数:pytest --alluredir report  # 在执行命令目录生成report文件夹,文件夹下包含json文件

 

在包里新建配置文件pytest.ini:

 1 [pytest]
 2 ;--html=./report.html
 3 ;删除原生html,增加Allure
 4 addopts = -s --alluredir report
 5 # 测试路径
 6 testpaths = ./Test
 7 # 测试文件名
 8 python_files = test_*.py
 9 # 测试类名
10 python_classes = Test_*
11 # 测试的方法名
12 python_functions = test_*

新建test_001.py:

 1 import allure
 2 import pytest
 3 
 4 
 5 class Test_Abc:
 6     @allure.step(title='第一个测试.')
 7     def test_abc_001(self):
 8         assert 1
 9 
10     @pytest.mark.parametrize('a', [0, 1, 2])
11     @allure.severity(allure.severity_level.CRITICAL)  # 严重级别(BLOCKER,CRITICAL,NORMAL,MINOR,TRIVIAL)
12     @allure.step(title='第二个测试.')
13     def test_abc_002(self, a):
14         allure.attach('描述', '我是测试步骤001的描述~~~')
15         assert a != 2
16 
17 
18 if __name__ == '__main__':
19     pytest.main("-s --alluredir report test_001.py")

 

操作步骤:

1.命令行进入pytest.ini所在目录

2.输入命令:pytest

执行结果:pytest.ini所在目录生成report文件夹,文件夹下生成一个或几个json文件

 

json转html:

1.进入report上级目录执行命令:allure generate report/ -o report/html

2.report目录下会生成index.html文件,即为可视化报告,用浏览器打开

 

posted @ 2020-05-17 22:14  jeyeshield  阅读(1544)  评论(3编辑  收藏  举报