当前位置: 首页 > wzjs >正文

烟台网站title优化深圳保障性住房在哪里申请

烟台网站title优化,深圳保障性住房在哪里申请,wordpress免费企业主题下载,天津房产信息网实现需求2:有两种运行测试的方式:通过config配置文件运行,测试只需要修改config配置文件cmdline 运行这里是新建一个config类来存储所有的测试配置,以后配置有修改的话也只需要修改这个类。根据目前的测试需求,config中…

实现需求2:

有两种运行测试的方式:

  1. 通过config配置文件运行,测试只需要修改config配置文件
  2. cmdline 运行

这里是新建一个config类来存储所有的测试配置,以后配置有修改的话也只需要修改这个类。

根据目前的测试需求,config中有以下几个属性:

属性作用备注
list_test        按case list的flag,为True时生效
single_test单条运行case的flag,为True时生效
repeat      

case重复运行的次数

risk_analysis高风险case分析功能暂未实现
tester              测试者的用户名,作为测试者发送邮件的收件人
case_list存储测试case集,从这里取出需要运行的测试

具体类代码为:

class TestConfig:"""测试配置管理"""_results_file = "test_results.json"_test_history = {}def __init__(self,list_test=False, single_test=False, repeat=1, case_list=None, risk_analysis=False,tester = None):self.list_test = list_testself.single_test = single_testself.repeat = repeatself.case_list = case_listself.risk_analysis = risk_analysisself.tester = tester

虽然有两种运行脚本的方式,但是通过这两种方式获取的信息都会填充到config这个类中,然后从这个类中读取当前需要运行的配置信息。 默认从配置文件中读取测试信息,当配置文件不存在时,从cmdline中读取测试信息。

图一 配置信息读取流程

最上层代码实现:

    def get_test_config(self, config):"""1. read config from config file2. check flag of test config . if true , read test config from config fileif false , read test config from cmdline:param config: Object of Class TestConfig"""split_str = "="config_list = self.read_config_from_file(CONFIG_FILE)run_from_cfg_file = ast.literal_eval(config_list[0].split(split_str)[1].strip())if run_from_cfg_file:logger.info("reading test config from config file ......")self.parse_settings_to_config(config_list, config)else:self.read_config_from_cmdline(config)logger.info("getting test config from cmdline ......")

读取配置文件

配置文件中包含两类信息:

  1. 当前配置文件是否有效的flag(True or False),后面会根据这个flag来决定读取config file还是cmdline
  2. 测试的具体信息,用于填充TestConfig对象的

代码实现:返回一个包含配置信息的list

    def read_config_from_file(self, file_path):# config_file = "config_file.txt"# # get path of config_file.txt# file_path = os.path.join(os.getcwd(), config_file)config_list = []# check if config file is exist# if self.__file_exist_check(file_path):if self.config_file_status(file_path):try:with open(file_path) as file_handle:lines = file_handle.readlines()for line in lines:config_list.append(line.strip())except FileNotFoundError as e:logger.exception(f"file not found:{e}")except PermissionError as e:logger.exception(f"No permission to read the file:{e}")except Exception as e:logger.exception(f"file not found: {e}")return config_list   # config_list 正确else:logger.error("Config file is not exist....Please check again,Test Stop......")exit()

配置文件config_file.txt的内容为:

 --use_config=False
--list_test=True
--single_test=False
--case_list =test_list.txt
--repeat=15
--risk_analysis=False
--tester=TestUser

判断是否使用配置文件

通过run_from_cfg_file 这个flag来判断是读取配置文件还是读取cmdline

"""flag of run method ,from config file , or from cmdline
"""
run_from_cfg_file = False# config_list 为read_config_from_file()返回的config list
run_from_cfg_file = ast.literal_eval(config_list[0].split(split_str)[1].strip())if run_from_cfg_file:logger.info("reading test config from config file ......")self.parse_settings_to_config(config_list, config)else:self.read_config_from_cmdline(config)logger.info("getting test config from cmdline ......")

若run_from_cfg_file 为True,则从配置文件中读取测试配置并调用方法parse_settings_to_config()填充到TestConfig对象中

# fill test settings to TestConfig objectdef parse_settings_to_config(self, arg_list, config):split_str = "="for item in arg_list:if "--list_test" in item:config.list_test = ast.literal_eval(item.split(split_str)[1].strip())  # transfer from string to bool typeelif "--single_test" in item:config.single_test = ast.literal_eval(item.split(split_str)[1].strip())  # transfer from string to bool typeelif "--case_list" in item:config.case_list = item.split(split_str)[1].strip()elif "--repeat" in item:config.repeat = item.split(split_str)[1].strip()elif "--risk_analysis" in item:config.risk_analysis = ast.literal_eval(item.split(split_str)[1].strip())  # transfer from string to bool typeelif "--tester=TestUser" in item:config.tester = item.split(split_str)[1].strip()

若run_from_cfg_file 为False,则调用方法read_config_from_cmdline()将cmdline中的配置填充到TestConfig配置中去。

 def get_cmdline_args(self):list = sys.argvreturn listdef read_config_from_cmdline(self,config):self.parse_settings_to_config(self.get_cmdline_args(),config)

至此通过配置文件和cmdline分别获取测试配置信息的task就已经完成了。读取配置信息的工作都是在tef_funtcion.py中的class FunctionApi中来完成的。完整代码为:

"""
this file is api preset for test, all test function tool that needed is included in this python file
"""
import ast
import os.path
import sysfrom utils.TestLogger import TestLogger as TestLoggerconfig_file = "config_file.txt"
# get path of config_file.txt
CONFIG_FILE = os.path.join(os.getcwd(), config_file)"""flag of run method ,from config file , or from cmdline
"""run_from_cfg_file = False
logger = TestLogger().get_logger()class FunctionApi:# fill test settings to TestConfig objectdef parse_settings_to_config(self, arg_list, config):split_str = "="for item in arg_list:if "--list_test" in item:config.list_test = ast.literal_eval(item.split(split_str)[1].strip())  # transfer from string to bool typeelif "--single_test" in item:config.single_test = ast.literal_eval(item.split(split_str)[1].strip())  # transfer from string to bool typeelif "--case_list" in item:config.case_list = item.split(split_str)[1].strip()elif "--repeat" in item:config.repeat = item.split(split_str)[1].strip()elif "--risk_analysis" in item:config.risk_analysis = ast.literal_eval(item.split(split_str)[1].strip())  # transfer from string to bool typeelif "--tester=TestUser" in item:config.tester = item.split(split_str)[1].strip()def get_cmdline_args(self):list = sys.argvreturn listdef read_config_from_cmdline(self,config):self.parse_settings_to_config(self.get_cmdline_args(),config)def __file_exist_check(self, file_path):if os.path.exists(file_path):return Trueelse:logger.error(f"File {file_path} does not exist.")return Falsedef read_case_from_list_file(self):test_list = "test_list.txt"# get path of test_list.txtfile_path = os.path.join(os.getcwd(), test_list)# print("os.path.abspath:", os.path.abspath(__file__))  #获取当前文件的绝对路径C:\code\USBTestAndroid\utils\api.py# print("os.getcwd()", os.getcwd())                     #获取调用该函数的项目路径C:\code\USBTestAndroid# print("file path :", file_path)case_list = []try:with open(file_path) as file_handle:lines = file_handle.readlines()for line in lines:case_list.append(line.strip())except FileNotFoundError as e:logger.error(f"file not found:{e}")except PermissionError as e:logger.error(f"No permission to read the file:{e}")except Exception as e:logger.error(f"file not found: {e}")return case_listdef config_file_status(self, file_path):"""check if config file is exist:return: True ,exist;False not exist"""return self.__file_exist_check(file_path)def read_config_from_file(self, file_path):config_list = []if self.config_file_status(file_path):try:with open(file_path) as file_handle:lines = file_handle.readlines()for line in lines:config_list.append(line.strip())except FileNotFoundError as e:logger.exception(f"file not found:{e}")except PermissionError as e:logger.exception(f"No permission to read the file:{e}")except Exception as e:logger.exception(f"file not found: {e}")return config_list   # config_list 正确else:logger.error("Config file is not exist....Please check again,Test Stop......")exit()def get_test_config(self, config):"""1. read config from config file2. check flag of test config . if true , read test config from config fileif false , read test config from cmdline:param config: Object of Class TestConfig"""split_str = "="config_list = self.read_config_from_file(CONFIG_FILE)run_from_cfg_file = ast.literal_eval(config_list[0].split(split_str)[1].strip())if run_from_cfg_file:logger.info("reading test config from config file ......")self.parse_settings_to_config(config_list, config)else:self.read_config_from_cmdline(config)logger.info("getting test config from cmdline ......")

下面的工作就是利用读取到的配置信息开始测试。

run_test.py:

    logger.info("Starting test execution...")config = TestConfig()functionApi.get_test_config(config)run_pytest(config)


文章转载自:

http://4VkRm96w.qwzpd.cn
http://QrvzwVeX.qwzpd.cn
http://iazBx7xg.qwzpd.cn
http://GpEWqufj.qwzpd.cn
http://QGkI0S9T.qwzpd.cn
http://7zOMqpmx.qwzpd.cn
http://kNA4U61x.qwzpd.cn
http://0CmmXr8k.qwzpd.cn
http://JBqONbzA.qwzpd.cn
http://JfutkcN2.qwzpd.cn
http://MvSFh1aZ.qwzpd.cn
http://GgannzGr.qwzpd.cn
http://wOsb1kJR.qwzpd.cn
http://CFaMzAnX.qwzpd.cn
http://U7K6U5dg.qwzpd.cn
http://Gyv50F1v.qwzpd.cn
http://7kozGu0H.qwzpd.cn
http://qunD1cEP.qwzpd.cn
http://tGUsdEaV.qwzpd.cn
http://QOjhvWke.qwzpd.cn
http://p17WAVEm.qwzpd.cn
http://GGs4mrMX.qwzpd.cn
http://p3QYM6O5.qwzpd.cn
http://YxlTIDw8.qwzpd.cn
http://W9hQ1ltJ.qwzpd.cn
http://fypgIm8m.qwzpd.cn
http://qmGQzDhx.qwzpd.cn
http://dsoVUuct.qwzpd.cn
http://Bm81n0Tb.qwzpd.cn
http://xzHXZay5.qwzpd.cn
http://www.dtcms.com/wzjs/772871.html

相关文章:

  • 中小企业网站建设客户需求调查问卷鲜花店网站源码
  • 密云网站制作案例营销型平台网站
  • 做云图的网站没有数据库的网站
  • 做网站哪家chatgpt app
  • 为什么企业要建设网站wordpress代码语言
  • eclipse网站开发教程有那种网站的浏览器
  • 网站建设公司小程序东高端莞商城网站建设
  • dede网站地图模板怎么在百度建立公司网站
  • 南通市住房和城乡建设厅网站国外单栏wordpress
  • 湖北网站设计制作多少钱查建设公司年度保证金网站
  • 权威的大连网站建设北京科技软件公司
  • 郑州微网站建设公司网页制作的教程视频
  • 网站制作教程dw生产企业网站如何做seo
  • 89点班组建设网站重庆专业网站营销
  • wordpress 三站合一阿里网站
  • linux下做网站竞价排名点击
  • 企业大型网站开发网站模板设计discuz论坛
  • 酒泉网站建设公司欧洲网站服务器
  • 网站建设 推广薪资岭南地区网站建设
  • 菏泽网站建设费用坂田公司做网站
  • 齐河县建设局网站向网站上传文件怎么做
  • 政务服务和数字化建设局网站高端网站建设 上海
  • 济南行业网站建设国家商标注册网查询官网
  • 网站空间与服务器天津住房和城乡建设厅网站
  • 可以做围棋习题的网站美食网站建设需求分析
  • 做网站的公司成本便宜的云服务器租用
  • 怎样做 云知梦 网站建设官网的网站首页
  • 网站没有备案怎么做支付淘点金 wordpress
  • 台州建设信息港网站传奇代理平台
  • 网站建设的技巧网站的icp备案信息