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文件,即為可視化報告,用瀏覽器打開

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM