python生成测试报告HTMLTestRunner时报错ValueError: write to closed file的解决办法

使用HTMLTestRunner时出现了以下问题:

    self.stream.write(output.encode('utf8'))
  ValueError: write to closed file

 原因是写入已经被关闭的文件导致报错,因为with open是自动保存的。

解决办法一:

  runner必须同样在with open下进行

  

扫描二维码关注公众号,回复: 7923867 查看本文章

 解决办法二

  不使用with open,直接使用open方法:(一开始就尝试的这种方法)

  

猜你喜欢

转载自www.cnblogs.com/chuiyuedefeng/p/11902018.html