python自动化测试代码结果_【自动化】:python自动化测试,生成测试报告内容为空的问题...
一、自动化测试中,生成测试报告并邮件发送,发现生成的测试报告内容为空: 当时的代码结构是:if __name__ == '__main__':test_app = "./"now_time = time.strftime("%Y_%m_%d_%H_%M_%S")fp = open(test_app+"/report/reportdata/"+now_time+"result.html", 'wb'
一、自动化测试中,生成测试报告并邮件发送,发现生成的测试报告内容为空:
当时的代码结构是:
if __name__ == '__main__':
test_app = "./"
now_time = time.strftime("%Y_%m_%d_%H_%M_%S")
fp = open(test_app+"/report/reportdata/"+now_time+"result.html", 'wb')
runner = HTMLTestRunner(fp,
title="XX系统测试报告",
description="运行环境:windows 10, firefox")
discover = unittest.defaultTestLoader.discover(test_app+"/test_case", pattern='*_sta.py')
runner.run(discover)
file_path = get_new_file('./report/reportdata/')
print("发送文件的路径", file_path)
send_mail(file_path)
原因是,在打开文件fp后,未关闭,增加fp.close()
if __name__ == '__main__':
test_app = "./"
now_time = time.strftime("%Y_%m_%d_%H_%M_%S")
fp = open(test_app+"/report/reportdata/"+now_time+"result.html", 'wb')
runner = HTMLTestRunner(fp,
title="XX系统测试报告",
description="运行环境:windows 10, firefox")
discover = unittest.defaultTestLoader.discover(test_app+"/test_case", pattern='*_sta.py')
runner.run(discover)
file_path = get_new_file('./report/reportdata/')
print("发送文件的路径", file_path)
fp.close()
send_mail(file_path)
二、调整后,代码如下,结果如下
更多推荐




所有评论(0)