一、安裝pytest
Pytest是Python的單元測試框架,非常方便和易用。可以規模化以及編寫更加複雜的測試用例。安裝方法如下:
pip install pytest
二、安裝allure插件
網上很多文檔說插件使用pytest-allure-adaptor
,單我目前使用python3如果安裝這個則會出現如下錯誤:
module 'pytest' has no attribute 'allure'
網上搜索了下,換成使用allure-pytest
即可;
安裝語句:
pip install allure-pytest
三、安裝allure-commandline
此工具是用於命令行生成allure報告的工具,官方下載鏈接:https://bintray.com/qameta/generic/allure2
此工具是基於java1.8的,故請確保在機器上安裝了java1.8以上的版本;
解壓後將其加入到環境變量中:
四、爲pytest用例添加allure註解
allure有許多註解和方法可以使用,在pytest腳本中加入import allure
即可使用,
例如:
@allure.feature("智能調度臺操作")
四、生成allure報告
使用如下命令可以生成allure的xml:
pytest -s -q --alluredir [xml_report_path]
//[xml_report_path]根據自己需要定義文件夾,如:/report/xml
而後可以在xml文件夾中看到很多的xml文件,而後就可以生成allure報告了,如下:
allure generate [xml_report_path] -o [html_report_path]
//[html_report_path]根據自己需要定義文件夾,例如:/report/html
而後在html文件夾中可以找到一個index.html文件,點擊打開即可看到如下類似頁面: