一、環境:
1、python3
2、pytest (一定別選最新的,4.0.2親測可用,否則會跳到坑二;還有項目名千萬別以pytest開頭)
3、allure(github下載:https://github.com/allure-framework/allure2/releases/tag/2.10.0)
注意:下載解壓完之后,記得切到bin目錄下,拷貝地址;添加到環境變量path下(重啟電腦生效---檢驗成功cmd下輸入allure,如下截圖環境OK)
4、pytest-allure-adaptor(pip pytest-allure-adaptor)
二、准備代碼
import pytest
# 不帶參數是默認scope='function'
@pytest.fixture()
def login():
print('輸入賬號和密碼')
def test_01(login):
print('test1----')
def test_02():
print('test2----不登錄')
def test_03(login):
print('test3----')
if __name__ == '__main__':
pytest.main(['-s', 'test_001.py'])
三、運行(cmd)
1、切到代碼所在目錄下:(dir看得見就可以)
py.test --alluredir=reports(成功執行后,會在case所在目錄下生成reports文件,里面有文件OK)
2.生成html
allure generate reports(會在case所在目錄生成文件夾,進入打開index.html--記得用火狐哦,谷歌是loading和404,哈哈哈哈)
添加用例后,更新allure-reports:
allure generate reports --clean
備注:報告的生成路徑,也可以自定義
一個報告弄了2次,再次感謝前輩的踩坑記錄,我才能填坑成功;記錄下,萬一換個電腦呢---
參考博客:
https://www.cnblogs.com/lza945/p/10323595.html
https://blog.csdn.net/sinat_40831240/article/details/89711263(坑一)