def is_result_pass(): file_name = Conf.get_report_path() + os.sep + "html/widgets/summary.json" with open(file_name, encoding='UTF-8') as f: data = json.load(f) fail_num = data["statistic"]["failed"] if fail_num == 0: log.info("接口测试通过") return True else: log.error("接口有报错") return False
def allure_report(report_path, report_html): """ 生成allure报告 @param report_path: @param report_html: @return: """ report_env_conf = Conf.get_report_path( ) + os.sep + "environment.properties" # 执行命令 allure generate # allure_cmd = # subprocess 执行命令 allure_cmd = "allure generate %s -o %s --clean" % (report_path, report_html) log.info("报告地址:%s" % report_path) copy_allure_environment_cmd = "cp %s %s" % (report_env_conf, report_path) res = subprocess.call(allure_cmd, shell=True) res_env = subprocess.call(copy_allure_environment_cmd, shell=True) try: if res == 0: log.info("allure报告生成成功!") except: log.error("执行用例失败,请检查一下测试环境配置") raise
import os import pytest from common import Base from config import Conf if __name__ == '__main__': report_path = Conf.get_report_path()+os.sep+"result" report_html_path = Conf.get_report_path()+os.sep+"html" pytest.main(["-s","--alluredir",report_path]) #Base.send_mail()
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # author:laobai # datetime:2020/5/1 01:38 import os import pytest from config import Conf if __name__ == '__main__': report_path = Conf.get_report_path() + os.sep + 'report' report_html_path = Conf.get_report_path() + os.sep + 'html' pytest.main(['-s','--alluredir',report_path])
#coding=utf-8 import os import pytest from common import Base from common.Base import zip_new_report from config import Conf import datetime if __name__ == '__main__': # 定义result和html的绝对路径 current_time = datetime.datetime.now().strftime("%A-%Y-%m-%d#%H-%M-%S") report_result_path = Conf.get_report_path( ) + os.sep + "result" + os.sep + current_time report_html_path = Conf.get_report_path( ) + os.sep + "html" + os.sep + current_time # 执行测试用例 pytest.main([ "-s", "./testcase/test_case_module_login/test_feed_login.py", "--alluredir", report_result_path ]) # 生成测试报告 Base.allure_report(report_result_path, report_html_path) # 打包测试报告 new_zip_report_path = zip_new_report()