python3+pytest+allure環境搭建

前沿:之前用的接口測試框架,主要用python3+request+unnitest+HTMLRunner組成,效率不是很高;後來重新規劃了一下,將其重構成python3+request+pytest+allure的版本,更加簡單易用,效率更高,報告也更加美觀;本教程先來說說其環境的搭建!

環境:windows 10、Python3.7(Python3的安裝請自行百度)

一、安裝pytest

1)win+R,輸入cmd

2)在dos窗口中,輸入:pip install pytest

3)安裝完成後,可以查看一下版本:pytest --version


python3+pytest+allure環境搭建


python3+pytest+allure環境搭建


python3+pytest+allure環境搭建

二、安裝allure-pytest

1)在dos窗口中,輸入:pip install allure-pytest

2)自動安裝完成後,會出現版本號安裝成功的提示信息


python3+pytest+allure環境搭建

三、安裝allure

1)自行百度下載(allure官網)

2)解壓後,找到bin目錄,然後進行環境變量的配置

環境變量:桌面-->此電腦-->右擊-->屬性-->高級系統設置-->環境變量-->系統變量-->編輯

3)新增環境變量的目錄,例如:D:\\work\\allure-2.7.0\\bin

4)配置成功後,打開一個新的dos窗口,如果配置成功,輸入allure,會有相關提示信息出來


python3+pytest+allure環境搭建


python3+pytest+allure環境搭建


python3+pytest+allure環境搭建


python3+pytest+allure環境搭建

四、在編譯器上,編寫一下簡單的驗證代碼,並執行一下

<code>import pytest
import allure

@allure.feature("myfirst allure")
def test_one():
print("hello pytest")
assert 1>2
if __name__ == '__main__':
pytest.main(['-s','test_01.py','-q','--alluredir','./report'])/<code>


python3+pytest+allure環境搭建

五、生成美觀的測試報告可視化展示

1)打開新的dos窗口,切換到驗證文件的目錄下(用dir命令),然後執行:allure generate --clean ./report -o ./results

2)在dos窗口中執行:allure open ./results或者allure serve ./report

3)執行後,就會默認瀏覽器彈出測試報告可視化展示


python3+pytest+allure環境搭建


python3+pytest+allure環境搭建

python3+pytest+allure環境搭建

python3+pytest+allure環境搭建

六、環境搭建完成

後續將繼續介紹,Python3+pytest+allure接口測試框架的搭建


分享到:


相關文章: