def run(self): last_time_fail_case_fo = codecs.open('last_time_fail.txt','w','utf-8') seed_logger.info("Start run all test case.") run_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) start_time = time.clock() if(seed.seed_setup): seed.seed_setup() for suit in TestSuit.test_suit_arr: if not os.path.exists(suit.suit_log_dir): os.makedirs(suit.suit_log_dir) suit_log_file_name = os.path.join(suit.suit_log_dir,suit.suit_name+'.log') self.init_log_config(suit_log_file_name) logging.info("*"*20+"["+suit.suit_name+' begin time:'+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))+']'+"*"*20) if(suit.suit_setup): suit.suit_setup() for test_case in suit.test_case_arr: run_res = None if self.check_case_can_rerun(test_case) and self.check_case_tag_can_run(test_case): test_case.case_log_path = os.path.join(suit.suit_log_dir,test_case.id+'.log') self.init_log_config(test_case.case_log_path) logging.info("*"*20+"["+test_case.desc+' begin time:'+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))+']'+"*"*20) seed_logger.info("Start run case id [{0}].".format(test_case.id)) run_res = test_case.run() seed_logger.info("case id [{0}] run finished.".format(test_case.id)) logging.info("*"*20+"["+test_case.desc+' end time:'+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))+']'+"*"*20+'\n'*2) logging.root.handlers = [] else: seed_logger.info("case id [{0}] is filtered.".format(test_case.id)) continue if not run_res.passed: last_time_fail_case_fo.write("{0}\n".format(test_case.id)) if(suit.suit_teardown): suit_log_file_name = os.path.join(suit.suit_log_dir,suit.suit_name+'.log') self.init_log_config(suit_log_file_name) suit.suit_teardown() logging.info("*"*20+"["+suit.suit_name+' end time:'+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))+']'+"*"*20+'\n'*2) logging.root.handlers = [] if(seed.seed_teardown): seed.seed_teardown() end_time = time.clock() seed_logger.info("All test case run finished.") last_time_fail_case_fo.close() return TotalResult(TestSuit.test_suit_arr,end_time-start_time,run_time)
def __init__(self,suit_name,suit_setup = None,suit_teardown = None): if TestSuit.is_exists(suit_name): sys.exit("no test suit and case!") seed_logger.info("create test suit:{0}".format(suit_name)) self.suit_name = suit_name self.suit_setup = suit_setup self.suit_teardown = suit_teardown self.test_case_arr = [] self.suit_log_dir = os.path.join('logs',suit_name) TestSuit.test_suit_arr.append(self)
def recombine_suits(self): test_suits = TestSuit.test_suit_arr n = len(test_suits) while n: suit = test_suits[n-1] test_cases = suit.test_case_arr i = len(test_cases) while i: seed_logger.info("******test case id [{0}].".format(test_cases[i-1].id)) seed_logger.info("******test case can run?: [{0}].".format(self.check_case_can_rerun(test_cases[i-1]))) seed_logger.info("******test case tag can run?: [{0}].".format(self.check_case_tag_can_run(test_cases[i-1]))) if not self.check_case_can_rerun(test_cases[i-1]) or not self.check_case_tag_can_run(test_cases[i-1]): seed_logger.info("remove a test case [{0}].".format(test_cases[i-1].id)) del test_cases[i-1] i -= 1 if not suit.test_case_arr: seed_logger.info("test suit lenth is [{0}],remove a test suit [{1}].".format(len(suit.test_case_arr),suit.suit_name)) TestSuit.test_suit_arr.remove(suit) n -= 1
def add_case(self,test_case_dict,case_run_fun): self.test_case_arr.append(TestCase(test_case_dict,case_run_method = case_run_fun)) seed_logger.info("create test case id:[{0}] in suit:[{1}]".format(test_case_dict['id'],self.suit_name))