HTMLTestRunner write()参数必须是str,而不是字节

时间:2017-10-16 12:14:36

标签: python-3.x selenium

我使用与python 3.5兼容的HTMLRunner 1.1.1

我的代码是:

dir=os.getcwd()
photo_tests=unittest.TestLoader().loadTestsFromTestCase(Photo_Tests.Photo_Test)
photo_tests_suit=unittest.TestSuite([photo_tests])

outfile=open(dir+"/Phototests.html","w")
runner=HTMLTestRunner.HTMLTestRunner(stream=outfile,title="Tests with facebook photos")

runner.run(photo_tests_suit)

每次运行时,我都会收到错误:

File "/home/akop/py_workspace/MacPaw_FB/Photos_tests/TestsWithreport.py", line 13, in <module>
    runner.run(photo_tests_suit)
  File "/usr/lib/python3.5/HTMLTestRunner.py", line 601, in run
    self.generateReport(test, result)
  File "/usr/lib/python3.5/HTMLTestRunner.py", line 658, in generateReport
    self.stream.write(output.encode('utf8'))
TypeError: write() argument must be str, not bytes

1 个答案:

答案 0 :(得分:0)

这是我在out.println(Organization1.name); out.println("$"+Organization1.revenue); out.println("For Profit: "+Organization1.profit); out.println(); out.println(Organization2.name); out.println("$"+Organization2.revenue); out.println("For Profit: "+Organization2.profit); out.println(); out.println(Organization3.name); out.println("$"+Organization3.revenue); out.println("For Profit: "+Organization3.profit); out.println(); out.println(Organization4.name); out.println("$"+Organization4.revenue); out.println("For Profit: "+Organization4.profit); out.println(); out.println(Organization5.name); out.println("$"+Organization5.revenue); out.println("For Profit: "+Organization5.profit); out.println(); out.println(Organization6.name); out.println("$"+Organization6.revenue); out.println("For Profit: "+Organization6.profit) 中的错误印刷 - 应该有&#34; wb&#34;而不是 - &#34; w&#34;