unittest解决测试用例中有错误时,发送邮件
unittest 解决运行case中报错,发送邮件的问题
报告模板「 htmlrunner」
# =================报告中有错误发送邮件 def is_result_pass(file_path): try: with open(file_path, "r",encoding='utf8') as fp: f = fp.read() # 读报告 soup = BeautifulSoup(f , "html.parser") status = soup.find_all(class_="attribute") result = status[2].contents[-1] # 获取报告结果 if "Failure" in result or "Error" in result: print("测试过程有不通过用例:%s" % result) return False else: return True except Exception as msg: print("判断过程出现异常:%s" % str(msg)) return False if not is_result_pass(file_path): send_mail(file_path) #调用发送邮件 else: print("全部通过,不发送邮件") print(file_path)
浙公网安备 33010602011771号