登錄接口的測試用例編寫
import pytest
from libs.login import Login
from utils.handle_excel import get_excel_data
from utils.handle_path import report_path
import allure
import os
#1-登錄類
@allure.epic('外賣系統')#工程級別--項目級別
@allure.feature('登錄模塊')#業務級別
class TestLogin:
#2-登錄的方法
@pytest.mark.parametrize('title,req_body,exp_resp',get_excel_data('登錄模塊','Login'))
@allure.story('登錄接口') # 接口級別
@allure.title('{title}') # 用例標題
def test_login(self,title,req_body,exp_resp):
res = Login().login(req_body)#3-調用登錄的接口
#4-斷言結果是否符合預期
assert res['msg'] == exp_resp['msg']
if __name__ == '__main__':#ctrl+j
#--clean-alluredir #清除之前的報告數據
pytest.main([__file__,'-s','--alluredir',report_path,'--clean-alluredir'])
os.system(f'allure serve {report_path}')
"""
- allure 跨平臺性
- 運行原理:
1- 報告需要數據源 pytest執行後生成的xxx.json文件
2- 使用allure serve 運行這些json文件
"""
結果報告: