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] 看不懂是什么意思,求大神解答
迷茫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.
self.errors[-1]
是最后一个 errors 也就是通过TestResult.addError(self, test, err)
Increased errors.
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.
Becausehtmltestrunner
my 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,
# )