所以我用Selenium和python运行测试用例,我想为这些测试生成HTML测试报告。我发现这个资源应该为我做,http://tungwaiyip.info/software/HTMLTestRunner.html如果有人感兴趣,它似乎真的很好,但我不断得到这个错误。

File "facebook.py", line 21, in <module>
HTMLTestRunner.main()
File "C:\Users\kporika\AppData\Local\Programs\Python\Python35-32\lib\unittest\main.py", line 94, in __init__
self.runTests()
File "C:\Users\kporika\PycharmProjects\Partha\HTMLTestRunner.py", line 816, in runTests
unittest.TestProgram.runTests(self)
File "C:\Users\kporika\AppData\Local\Programs\Python\Python35-32\lib\unittest\main.py", line 255, in runTests
self.result = testRunner.run(self.test)
File "C:\Users\kporika\PycharmProjects\Partha\HTMLTestRunner.py", line 631, in run
self.generateReport(test, result)
File "C:\Users\kporika\PycharmProjects\Partha\HTMLTestRunner.py", line 688, in generateReport
self.stream.write(output.encode('UTF-16'))
TypeError: write() argument must be str, not bytes

测试报告生成器的代码在这里https://github.com/tungwaiyip/HTMLTestRunner/blob/master/HTMLTestRunner.py是创建者的github页面。我该怎么解决?
ps如果有帮助的话,我正在运行python 3.5版。

最佳答案

HTMLTestRunner是python2模块。Python3区分strbytes对象,而python2有unicodestr对象。
如错误消息所示,第688行需要一个str,而不是bytes对象。作为the documentation clarifiesstr.encodestr对象转换为bytes对象。您需要将第688行修改为self.stream.write(output.encode('UTF-16')),而不是self.stream.write(output)
注意,由于python2/3不兼容,很可能会有更多的错误。

09-16 17:10