H5W3
当前位置:H5W3 > 其他技术问题 > 正文

为什么使用HTMLTestrunner有时候报错,有时候不报错?

最近写了unittest+HTMLtestrunner生成网页版的测试报告,偶然发现了如下报错

File "/usr/lib/python2.7/site-packages/cephmgmtclient/sds_cli_auto_test/HTMLTestRunner.py", line 558, in complete_output
    return self.outputBuffer.getvalue()
AttributeError: '_TestResult' object has no attribute 'outputBuffer'

但是同样是python2.7,我在另一个环境就不会报错,求大神帮忙看看
我在网上查了,修改了代码,如下

class _TestResult(TestResult):
    # note: _TestResult is a pure representation of results.
    # It lacks the output and reporting ability compares to unittest._TextTestResult.

    def __init__(self, verbosity=1):
        TestResult.__init__(self)
        self.stdout0 = None
        self.stderr0 = None
        self.success_count = 0
        self.failure_count = 0
        self.error_count = 0
        self.verbosity = verbosity

        # result is a list of result in 4 tuple
        # (
        #   result code (0: success; 1: fail; 2: error),
        #   TestCase object,
        #   Test output (byte string),
        #   stack trace,
        # )
        self.result = []
        self.outputBuffer = io.BytesIO()
        #self.test_start_time = round(time.time(), 2)

虽然不报错了,但是我的测试一个用例都没跑就退出了,打印如下

Begin to run test_template 1 and apply the job map

E  setUpClass (__main__.Test_case01)

Time Elapsed: 0:00:00.013564

不知道是什么原因啊!

本文地址:H5W3 » 为什么使用HTMLTestrunner有时候报错,有时候不报错?

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址