python类库依赖:
pip3 install pytest
pip3 install allure-pytest
pip3 install rerequests
pip3 install pytest-repeat
环境依赖
linux:
jdk8环境
安装allure文件
npm install -g allure-commandline --save-dev
增加软连接
验证
allure --version
import requests, os, sys, pytest,allure @pytest.fixture def test_garbfilter_preposition(self): ''' 广告词检测前置条件 :return: ''' yield self.test_garbfilter_preposition # 清除测试数据-解除禁言 with requests.post(delforbidinfo_url(), headers=chat_header(), json={ "roleId": 'Advertising_data' })as delfor: assert_correct_method(delfor) @pytest.mark.skipif(Advertising_conditions(), reason="请求参数:" + str(Advertising_data()[1]) + "\r\n发送广告禁言测试条件不满足跳过此用例,条件请求返回值:" + str( Advertising_data()[0]) + "") @allure.story('禁言后发言') def test_garbfilter_true(self, test_garbfilter_preposition): ''' :return: {'code': 486, 'info': 'forbidden speak'} ''' data={ "from": 'Advertising_data', "to": "p:dc_ceshi", "msgType": 1, "body": "发送消息", "ext": { "key": "value" }, "garbFilter": True, "wordFilter": True, "time": request_time() } with allure.step("请求参数:%s 请求地址%s" % (data, sendmsg_url())): with requests.post(sendmsg_url(), headers=chat_header(), json=data) as send_s: with allure.step("返回参数:%s" % send_s.json()): assert_forbid_method(send_s)
运行指令 run.py
if __name__ == '__main__': pytest.main(['-v', '-s',curPath+'/test_cases', '--alluredir', curPath+'/report/report', '--clean-alluredir']) while 1: try: os.system('allure generate '+curPath+'/report/report -o '+curPath+'/report/allure-reports/ --clean') break except Exception: print('等待生成静态文件...') finally: time.sleep(1)