Mac上下载、配置、修改HTMLTestRunner使其支持Python3环境

  1. HTMLTestRunner下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html
    打开链接后可看到如图,选择HTMLTestRunner.py右键点击另存为到本地。
    Mac上下载、配置、修改HTMLTestRunner使其支持Python3环境

  2. 打开终端,找到Python安装目录。(由于我自己安装了Python3.6,所以安装目录的路径不是在dist-package下)
    Mac上下载、配置、修改HTMLTestRunner使其支持Python3环境

  3. 将下载的HTMLTestRunner.py移动到/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages该路径下。脚本上输入import HTMLTestRunner不报错,说明添加成功。
    a、使用命令:
    cp HTMLTestRunner.py /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
    b、直接移动

  4. 由于HTMLTestRunner.py基于python2开发,为让其支持python3环境,需对其中的部分内容进行修改。
    a、94行 import StringIO 修改为 import io
    b、539行 self.outputBuffer = StringIO.StringIO() 修改为 self.outputBuffer = io.StringIO()
    c、631行 print >>sys.stderr, ‘\nTime Elapsed: %s’ % (self.stopTime-self.startTime) 修改为 print(sys.stderr, ‘\nTime Elapsed: %s’ % (self.stopTime-self.startTime))
    d、642行 if not rmap.has_key(cls): 修改为 if not cls in rmap:
    e、766行 uo = o.decode(‘latin-1’) 修改为 uo = o
    f、772行 ue = e.decode(‘latin-1’) 修改为 ue = e