python - htmltestrunner源码有一处不太理解,求助
PHP中文网
PHP中文网 2017-04-17 17:59:26
0
1
302
    self.error_count += 1
    TestResult.addError(self, test, err)
    _, _exc_str = self.errors[-1]
    output = self.complete_output()
    self.result.append((2, test, output, _exc_str))
    if self.verbosity > 1:
        sys.stderr.write('E  ')
        sys.stderr.write(str(test))
        sys.stderr.write('\n')
    else:
        sys.stderr.write('E')
        

其中第三行的 _, _exc_str = self.errors[-1] 看不懂是什么意思,求大神解答

PHP中文网
PHP中文网

认证高级PHP讲师

membalas semua(1)
迷茫

从来没用过, 只能看一下源码,是对unittest的一些拓展.

  1. self.errors[-1]是最后一个 errors 也就是通过TestResult.addError(self, test, err)增加的errors.

  2. errors 参考 https://docs.python.org/2.7/library/unittest.html#unittest.TestResult.errors

A list containing 2-tuples TestCase instances and strings holding formatted tracebacks.

是一个二元组的list, 元组中第一个是TestCase实例也就是这次赋值给_(需要忽略的内容) 第二个是tracebacks是这次需要的内容.

因为htmltestrunner自己的注释说

        # 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,
        # )
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!