1、测试环境及场景:
Python3.5+unittest+HTMLTestRunner
生成html报告时候报错
2、报错内容:
..Traceback (most recent call last):
File "D:/case/LAS/test_add_dele.py", line 25, in <module>
runner.run(suit)
File "D:setupPython35libHTMLTestRunner.py", line 630, in run
self.generateReport(test, result)
File "D:setupPython35libHTMLTestRunner.py", line 687, in generateReport
self.stream.write(output.encode('utf8'))
ValueError: write to closed file
如图所示:
3、解决方法:
截图中第19行fp文件的定义方法不对。
将上面截图中19--22行代码改成如下方式则可正常运行啦:
1 fp = open(report_name,"wb") 2 runner = HTMLTestRunner(stream=fp, 3 title="测试一下报告生成", 4 description="用两个数字的相加减来练习")
4、该脚本的完整无报错版本
可以看上篇文章,地址 https://www.cnblogs.com/zhengyihan1216/p/11549820.html