1.登录测试类
import pytest,allure,os
from libs.login import Login
from utils.handle_excel import get_excel_data
from utils import handle_path
from utils.handle_path import report_path
from common.baseApi import BaseAssert
@allure.epic('项目名称')
@allure.feature('业务模块名称')
class TestLogin(BaseAssert):
@pytest.mark.parametrize('inBody,expData', get_excel_data(
'../data/Delivery.xls', '登录模块', 'Login','请求参数','响应预期结果'))
@allure.story('登录接口')
@allure.title('用例标题2')
def test_login(self,inBody,expData):
res=Login().login(inBody)
self.define_assert(res['msg'],expData['msg'])
if __name__ == '__main__':
pytest.main([__file__,'-sv','--alluredir',report_path,'--clean-alluredir'])
os.system(f'allure serve {report_path}')
2.处理工程文件路径
import os
print(__file__)
print(os.path.dirname(__file__))
project_path=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(project_path)
data_path=os.path.join(project_path,'data')
log_path=os.path.join(project_path,'logs')
config_path=os.path.join(project_path,'configs')
report_path=os.path.join(project_path,'report')
if __name__ == '__main__':
print('工程:',project_path)
print('数据:',data_path)
print('日志:',log_path)
print('配置:',config_path)
print('报告:',report_path)