我有一个调用 python 方法的机器人框架测试套件。我希望该 python 方法在不通过测试的情况下向控制台返回一条消息。具体来说,我正在尝试对一个过程进行计时。
我可以使用“raise”向控制台返回一条消息,但同时测试失败。
def doSomething(self, testCFG={}):
'''
Do a process and time it.
'''
testCFG['operation'] = 'doSomething'
startTime = time.time()
response=self.Engine(testCFG)
endTime = time.time()
duration = int(round(endTime-startTime))
raise "doSomething took", duration//60 , "minutes and", duration%60, "seconds."
errmsg = 'doSomething failed'
if testCFG['code']: raise Exception(errmsg)
或者我可以使用“打印”将消息返回到日志文件并报告而不会使测试失败,但该信息仅在报告中可用,而不是在控制台中可用。
def doSomething(self, testCFG={}):
'''
Do a process and time it.
'''
testCFG['operation'] = 'doSomething'
startTime = time.time()
response=self.Engine(testCFG)
endTime = time.time()
duration = int(round(endTime-startTime))
print "doSomething took", duration//60 , "minutes and", duration%60, "seconds."
errmsg = 'doSomething failed'
if testCFG['code']: raise Exception(errmsg)
如果我使用“打印”选项,我会得到:
==============================================================================
Do Something :: Do a process to a thing(Slow Process). | PASS |
------------------------------------------------------------------------------
doSomething :: Overall Results | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
我想要的是这样的:
==============================================================================
Do Something :: Do a process to a thing(Slow Process). | PASS |
doSomething took 3 minutes and 14 seconds.
------------------------------------------------------------------------------
doSomething :: Overall Results | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================