Home  >  Q&A  >  body text

python - htmltestrunner源码有一处不太理解,求助

    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中文网2763 days ago344

reply all(1)I'll reply

  • 迷茫

    迷茫2017-04-17 18:01:26

    I have never used it, I can only take a look at the source code, which is some expansion of unittest.

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

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

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

    is a list of tuples. The first one in the tuple is the TestCase instance, which is what is assigned to _ this time (the content that needs to be ignored). The second one is tracebacks, which is what is needed this time.

    Becausehtmltestrunnermy own comment says

            # 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,
            # )

    reply
    0
  • Cancelreply