问题:

python 执行时报错

sortedResult = self.sortResult(result.result)
File "D:\Python39\lib\HTMLTestRunner.py", line 642, in sortResult
if not rmap.has_key(cls):
AttributeError: 'dict' object has no attribute 'has_key'
[Finished in 0.2s with exit code 1]

解决方案:

查阅资料发现,Python3以后删除了has_key()方法

打开HTMLTestRunner.py该文件第642行,将 if not rmap.has_key(cls):改为 if not cls in rmap: 保存

再次运行脚本时,成功。