class SaveData(object): _path = InitData().get_sys_path()["savepath"] + "/logs/tmp.log" def save(self, msg=None): '''写入的数据格式与 runTest的格式一致(中文名)''' if msg == None: print('不保存数据') return with open(SaveData._path, 'a+') as fn: fn.write(msg + '\n') def get_value(self): '''主要不错数据格式:中文名(case固定):时延''' # 读取文件 with open(SaveData._path, 'r') as fn: txt = fn.readlines() # 清空数据 with open(SaveData._path, 'w') as fn: fn.write("") txt2 = [] for line in txt: key = line.split(":")[0] value = line.split(":")[1][:-1] # print(key, value) txt2.append((key, value)) # 返回字典格式 return dict(txt2)
class ReadWriteConfFile: file_path = InitData().get_sys_path()['rwconf'] print(file_path) @staticmethod def get_config_parser(): cf=cparser.ConfigParser() cf.read(ReadWriteConfFile.file_path) return cf @staticmethod def write_config_parser(cf): f=open(ReadWriteConfFile.file_path,"w") cf.write(f) f.close() @staticmethod def get_section_value(section, key): cf=ReadWriteConfFile.get_config_parser() return cf.get(section, key) @staticmethod def add_section(section): cf=ReadWriteConfFile.get_config_parser() all_sections=cf.sections() if section in all_sections: return else: cf.add_section(section) ReadWriteConfFile.write_config_parser(cf) @staticmethod def set_section_value(section, key, value): cf=ReadWriteConfFile.get_config_parser() cf.set(section, key, value) ReadWriteConfFile.write_config_parser(cf)
import unittest,os,sys # 添加环境路径,脚本 p = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) print("path: %s" %p) sys.path.append(p+"/") import time, datetime from src.base.baseTime import BaseTime from src.readwriteconf.initData import InitData from src.readwriteconf.saveData import save from src.reportlib.reportclass import ReportClass from src.testcase.HTMLTestRunner import HTMLTestRunner import random localPath = InitData().get_sys_path()["savepath"] # 信息存储路径 reportPath = localPath + "/reports/" logPath = localPath + "/logs/" iniPath = localPath + '/ini/' logfileName= BaseTime.get_date_hour() + '.log' class MyTest(unittest.TestCase): @classmethod
# urs/bin/python # encoding:utf-8 import unittest, time from src.psam.psamio import Psam from src.testcase.v318.basecase.send import Send from src.testcase.v318.basecase.login import Login from src.readwriteconf.initData import InitData from src.mail.mailOperation import EmailOperation d = InitData().get_users() username = d['user1'] pwd = d['pwd1'] username2 = d['user2'] pwd2 = d['pwd2'] receiver = {'name': username, 'pwd': pwd} sender = {'name': username2, 'pwd': pwd2} class TestSend(unittest.TestCase): def setUp(self): try: self.driver = Psam(is_install=False) except BaseException: self.fail("setUp启动出错!") else: EmailOperation(username + "@139.com", pwd).clear_forlder(['INBOX']) time.sleep(5)
from src.mail.sendEmailSmtp import SendMail import time, datetime import copy from src.base.baseTime import BaseTime from src.readwriteconf.rwconf import ReadWriteConfFile as rwc from src.readwriteconf.initData import InitData from src.readwriteconf.saveData import save from src.readwriteconf.calcSucPer import CalcSuccess from collections import Counter logPath = InitData().get_sys_path()["savepath"] + "/logs/" logfileName= BaseTime.get_date_hour() + '.log' # 原始记录 org_file_path = logPath + 'org_' + logfileName # 原始记录待样式 html_file_path = logPath + 'html_' + logfileName # 真实数据 tsave_file_path = logPath + 'savet_' + logfileName # 真实数据带样式 thtml_file_path = logPath + 'true_' + logfileName # 假数据 fsave_file_path = logPath + 'savef_' + logfileName # 假数据带样式 fhtml_file_path = logPath + 'false_' + logfileName class ReportClass(object): # 每一轮的错误次数 error_times= 0