Ejemplo n.º 1
0
    def test(self):
        self.setup()

        log.debug('now testing')

        result = TestResult()
        result.start_time = datetime.now()
        result.log = islog(self)
        log.debug('there are %s children in this testcase' %
                  len(self._children))
        for child in self._children:
            log.debug('calling child %s' % child._name)
            try:
                rs = child()
                self.setResult(child, result, rs)
                if rs.status in ['ERROR', 'FAIL']:
                    print '=============error======'
                    # 测试组件自检出错
                    result.status = rs.status
                    #result.exc_info = rs.exc_info
                    log.debug('Test Error')
                    break
            except:
                # 而非断言错误,测试组件没能自检出来
                import sys
                result.status = 'ERROR'
                result.exc_info = sys.exc_info()
                log.debug('Test Error')
                log_exce()
                break
        result.end_time = datetime.now()
        self.teardown()
        result.nodename = self.name
        return result
Ejemplo n.º 2
0
    def __init__(self,config=Config,result_handler=None,**kwargs):
        self.config = config
        
	if result_handler and getattr(result_handler,'handle',None):
            self.result_handler = result_handler
	else:
	    from resultHandler import xmlHandler
	    self.result_handler = xmlHandler()
	testdir = self.config.testdir
        # scan test file
        self.testcases = {} # 管理测试用例
	#self.testCasesFile = {}#文件与testcase对应

        for testfile in self.get_test_files():
        # 构造测试并添加,视情况看是否需要启用新定时器
            testcase = TestCase()
	    file_name = os.path.sep.join((os.getcwd(),testfile))
            try:
                xml = self.parsexml(testfile)
                testcase.fromxml(xml)
                if testcase.is_valid():
                    self.testcases[testcase.name] = testcase
		    self.file2testcase[file_name] = testcase.name
		    #后来添加
		    #self.testCasesFile[testfile] = testcase.name
                else:
                    raise Exception,'no testcase found of empty testcase'
            except:
                log_exce('invalid testcase definition in file : %s, will be discard.'%testfile)

        log.info('load test file done! there are %d valided testcases.'%len(self.testcases.keys()))
Ejemplo n.º 3
0
    def test(self):
        self.setup()

        log.debug('now testing')

        result = TestResult()
        result.start_time = datetime.now()
        result.log = islog(self)
        log.debug('there are %s children in this testcase'%len(self._children))
        for child in self._children:
            log.debug('calling child %s'%child._name)
            try:
                rs = child()
		self.setResult(child,result,rs)
                if rs.status in ['ERROR','FAIL']:
		    print '=============error======'
                    # 测试组件自检出错
                    result.status = rs.status
                    #result.exc_info = rs.exc_info
                    log.debug('Test Error')
                    break
            except:
                # 而非断言错误,测试组件没能自检出来
                import sys
                result.status = 'ERROR'
                result.exc_info = sys.exc_info()
                log.debug('Test Error')
                log_exce()
                break
        result.end_time = datetime.now()
        self.teardown()
        result.nodename = self.name
	return result
Ejemplo n.º 4
0
 def run(self):
     log.debug('about to run all test!')
     for name,testcase in self.testcases.items():
         try:
             thread = threading.Thread(target=testcase,name=name,kwargs={'config':self.config,'callback':self.handle_result})
             thread.start()
         except Exception,e:
             log_exce('testcase %s start fail.'%name)