目录
- 1.如何同时执行多个测试文件
- 2.Allure的不同层级应用
- Allure报告:
1.如何同时执行多个测试文件
(1)新建bat文件
(2)写命令
cd ./testCase
pytest -s --alluredir ./report --clean-alluredir
allure serve ./report
2.Allure的不同层级应用
Allure层级
(1)第一层:项目层@allure.epic
(2)第二层:模块层@allure.feature
(3)第三层:接口层@allure.story
(4)第四层:用例层@allure.title
import pytest,allure,os
from libs.login import Login
from utils.handle_excel import get_excel_data
from utils.handle_path import report_path
from utils.handle_path import data_path
from common.baseApi import BaseAssert
#TestLogin继承BaseAssert
@allure.epic('项目名称-外卖项目')
@allure.feature('商铺模块')
# @pytest.mark.skip(reason='该模块暂时不要运行')
@pytest.mark.skipif(1==2,reason='条件满足就跳过')
class TestShop(BaseAssert):
@pytest.mark.parametrize('title,inBody,expData', get_excel_data('商铺模块', 'Listshop','标题','请求参数','响应预期结果'))
@allure.story('商铺列表接口')
@allure.title("{title}")
@pytest.mark.shop_list
def test_shop_list(self,title,inBody,expData,shop_init):#shop_init初始化操作
# 1.调用业务层封装的接口代码
res=shop_init.query(inBody)
# 2.断言实际返回结果与预期结果
self.define_assert(res['code'],expData['code'])
@pytest.mark.parametrize('title,inBody,expData', get_excel_data('商铺模块', 'Updateshop','标题','请求参数','响应预期结果'))
@pytest.mark.shop_list
@allure.story('商铺编辑')
@allure.title("{title}")
def test_shop_update(self,title,inBody,expData,shop_init):
# 分步走
with allure.step('1.店铺实例'): #店铺实例
print('1.获取店铺实例')
with allure.step('2.店铺列出接口获取shopid'): #店铺列出接口获取shopid
shopID=shop_init.query({"page":1,"limit":2})['data']['records'][0]['id']
with allure.step('3.图片上传接口'):# 图片上传接口
resimage = shop_init.file_upload(data_path + '\\cat.jpg')
imageInfo = resimage['data']['realFileName']
with allure.step('4.调用编辑店铺接口'):
res=shop_init.update(inBody,shopID,imageInfo)
self.define_assert(res['code'],expData['code'])
if __name__ == '__main__':
pytest.main([__file__,'-sv','-m','shop_list or shop_update','--alluredir',report_path,'--clean-alluredir'])
os.system(f'allure serve {report_path}')