def nose_run(parser): Config.nose_set("verbosity", parser.verbosity) Config.nose_set("logging-config", Dir.log_config_path()) # 通过关键字筛选出来的用例列表 tests = FileHelper.tests_filter_from_dir(Dir.testcases_root_dir(), parser.select, parser.priority) Config.nose_set("where", Dir.testcases_root_dir()) if len(tests): for i in xrange(parser.loop): # 生成的报表每个名称都不一样,以时间为区分 nosexml = Dir.nose_result_path( ) + "wy_autotest_" + Datetime.now_str() + ".xml" Config.nose_set("tests", ",".join(tests)) Config.nose_set("xunit-file", nosexml) Logger.info("正在第{0}/{1}次进行Nose测试".format(i + 1, parser.loop)) Logger.info("执行Nose命令:{0}".format(Config.nose_cmd())) # 切换当前路径为工程根目录 os.chdir(Dir.project_root_dir()) os.system("nosetests") #发送邮件 result_summary = Result.test_result_summary(nosexml) result_detail = Result.test_result_detail(nosexml) rev_addr_lst = [ "*****@*****.**", "*****@*****.**", "*****@*****.**" ] Mail.send_email_with_attachment( result_summary + result_detail, Config.DefaultConfig().Email.Subject, nosexml, rev_addr_lst) Logger.info("完成第{0}/{1}次进行Nose测试".format(i + 1, parser.loop)) else: Logger.info("抱歉,没有符合条件的执行测试用例!")
def init(): # 修改日志配置文件的路径 f = open(Dir.log_config_path()) tag = "'.*_Output/log/wy_autotest\.log'" t_str = "_Output/log/wy_autotest.log'" content = f.read() f.close() f = open(Dir.log_config_path(), "w+") content = re.sub(tag, "'" + Dir.project_root_dir().replace("\\", '/') + t_str, content) f.write(content) f.close() # 加载日志配置文件 logging.config.fileConfig(Dir.log_config_path())
def nose_cmd(): nose_cfg_path = Dir.project_root_dir() + "nose.cfg" cf = ConfigParser.ConfigParser() cf.read(nose_cfg_path) return cf.items("nosetests")
def nose_set(key, value): nose_cfg_path = Dir.project_root_dir() + "nose.cfg" cf = ConfigParser.ConfigParser() cf.read(nose_cfg_path) cf.set("nosetests", key, value) cf.write(open(nose_cfg_path, "w"))