zoukankan      html  css  js  c++  java
  • 解决:python3.x引入HTMLTestRunner报错问题

    HTMLTestRunner是python2中的,由于python2与3的部分语法有改动,所以需要对下载的文件进行修改才能在python3中使用。

    1、下载文件:

    下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html  ,右键HTMLTestRunner.py文件另存为即可。

    下载后放到python安装目录/Lib下,如我的路径为:C:UsersXXXAppDataLocalProgramsPythonPython38Lib

    2、修改文件:

    第94行,将import StringIO修改成import io

    第539行,将self.outputBuffer = StringIO.StringIO()修改成self.outputBuffer = io.StringIO()

    第642行,将if not rmap.has_key(cls):修改成if not cls in rmap:

    第766行,将uo = o.decode('latin-1')修改成uo = e

    第772行,将ue = e.decode('latin-1')修改成ue = e

    第631行,将print >> sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime))

    3、引入使用:

    1)引包:from HTMLTestRunner import *

    2)使用,如:

    if __name__ == '__main__':
    report = REPORT_PATH + '\report.html'
    with open(report, 'wb') as f:
    runner = HTMLTestRunner(f, verbosity=2, title='Test', description='测试报告')
    runner.run(TestBaidu('test_search'))

    备注:1)中我最开始用的import HTMLTestRunner,执行的时候上述2)中倒数第二行报错:TypeError: 'module' object is not callable。
    度娘了下,发现2种方式使用时有区别,import module:使用时需加上模块名的限定,而from HTMLTestRunner import * 不需要加。如下2种方式都可以:

    1、
    from HTMLTestRunner import *
    runner
    = HTMLTestRunner(f, verbosity=2, title='Test', description='测试报告')
    2、
    import HTMLTestRunner
    runner = HTMLTestRunner.HTMLTestRunner(f, verbosity=2, title='Test', description='测试报告')


    3、在使用HTMLTestRunner时,报告为空,错误提示<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'>

    解决方案:将HTMLTestRunner脚本的第631行的 print >> sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime) 或print(sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime)) 修改为 sys.stderr.write(' Time Elapsed: %s ' % (self.stopTime - self.startTime))

     
  • 相关阅读:
    Python前言之Markdown使用
    Linux压缩命令
    ubuntu安装nodejs
    linux搭建nginx流服务器,OBS推流,VCL拉流播放
    nginx配置文件
    控制语句
    鼠标用户和键盘用户
    if else
    cookie自封装对象
    C#:基于WMI查询USB设备信息 及 Android设备厂商VID列表
  • 原文地址:https://www.cnblogs.com/syywy/p/13677047.html
Copyright © 2011-2022 走看看