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

做正规小说网站有哪些网站seo视频

做正规小说网站有哪些,网站seo视频,wordpress 底部导航,广东智唯网站建设公司1. 前言 在做自动化测试时,有些特殊项目需要连接不同的数据库进行造数或者断言。自动化框架中,一般使用Pytest yaml 数据驱动的居多,如果一个项目中有上百条数据库相关测试用例,在数据库测试时,如果设计不合理的连接模…

1. 前言

在做自动化测试时,有些特殊项目需要连接不同的数据库进行造数或者断言。自动化框架中,一般使用Pytest yaml 数据驱动的居多,如果一个项目中有上百条数据库相关测试用例,在数据库测试时,如果设计不合理的连接模式,可能会导致数据库连接数超长,从而导致连接失败。要如何设计合理的数据库连接管理机制,主要思考两个点:
  1、可以随便切换数据库
  2、连接过的数据库可以不需要再次连接

这里我们使用工厂模式和单例模式来解释这个。

2. 单例模式

单例模式是一种保证一个类只有一个实例的设计模式。在Pytest中,可以利用单例模式确保每种类型的数据库连接只生成一个实例,以便在整个测试过程中共享和复用这些连接对象。

代码示例:

# 写法1
class MySQLConnection:_instance = Nonedef __new__(cls):if cls._instance is None:cls._instance = super().__new__(cls)return cls._instancedef connect(self):# 连接到MySQL数据库的具体实现pass# 使用单例模式创建MySQL数据库连接对象
mysql_conn1 = MySQLConnection()
mysql_conn2 = MySQLConnection()print(mysql_conn1 is mysql_conn2)  # 输出:True
mysql_conn1.connect()
# 写法2、利用Python本身就是单实例对象
class MySQLConnection:def connect(self):# 连接到MySQL数据库的具体实现pass# 使用单例模式创建MySQL数据库连接对象
mysql_conn= MySQLConnection()
# 其他文件import 这个实例,也可以实现单实例
import mysql_conn

从上面代码可以看出,单实例就只能有一个实例化,如果我有不同的数据库要连接,这个单实例就适用了。

3. 工厂模式

工厂模式是一种创建对象的设计模式,在Pytest中可以用于根据需要创建不同配置的数据库连接对象。通过工厂模式,可以实现灵活的数据库连接管理,使得测试代码更易于维护和扩展。
代码示例:

class MysqlManagerFactory:""" 使用工厂模式解决多实例连接问题 """instances = {}@classmethoddef get_instance(cls, host, user):key = (host, user)if key not in cls.instances:print(f"New Connect to mysql!")cls.instances[key] = MysqlManager(*key)return cls.instances[key]class MysqlManager(object):def __init__(self, host,user):print(f"Connect to mysql sucess!")passif __name__ == '__main__':db = MysqlManagerFactory.get_instance(1,2)print(db)db1 = MysqlManagerFactory.get_instance(1,2)print(db1)db2 = MysqlManagerFactory.get_instance(2,3)print(db2)

从结果可以看到,第一个实例化话后,第二次连接,不需要再次实例化,如果是其他的配置再次实例化,则会再次重新连接

New Connect to mysql!
Connect to mysql sucess!
<__main__.MysqlManager object at 0x00000298DFCEECD0>
<__main__.MysqlManager object at 0x00000298DFCEECD0>
New Connect to mysql!
Connect to mysql sucess!
<__main__.MysqlManager object at 0x00000298DFCEEFD0>

总结:

单例模式确保每种类型的数据库连接只有一个实例,实现全局共享;而工厂模式则提供了灵活的对象创建机制,使得测试代码更具扩展性和可维护性。如果你想要看到完整的实现案例,可以查看我开源的Pytest 框架源码,这是一个关于如何设计一个适合你自己的简易框架,而不是教你如何用安装包来做接口自动化的CRUD。
https://gitee.com/itestxs/simple-pytest.git


文章转载自:
http://dinncoplexus.stkw.cn
http://dinncojol.stkw.cn
http://dinncoigbo.stkw.cn
http://dinncosternum.stkw.cn
http://dinncomelkite.stkw.cn
http://dinncoexsect.stkw.cn
http://dinncoworship.stkw.cn
http://dinncoheathendom.stkw.cn
http://dinncoamaranthine.stkw.cn
http://dinncochlorophyll.stkw.cn
http://dinncotagger.stkw.cn
http://dinncoproscenium.stkw.cn
http://dinncoepineurial.stkw.cn
http://dinncozelda.stkw.cn
http://dinncodisaffected.stkw.cn
http://dinncoadrenergic.stkw.cn
http://dinncoumbel.stkw.cn
http://dinncopausal.stkw.cn
http://dinncotentaculiform.stkw.cn
http://dinncogotha.stkw.cn
http://dinncodeferential.stkw.cn
http://dinncolongaeval.stkw.cn
http://dinncoanabasis.stkw.cn
http://dinncogarnish.stkw.cn
http://dinncobating.stkw.cn
http://dinncogossan.stkw.cn
http://dinncosemidomestic.stkw.cn
http://dinncourinogenital.stkw.cn
http://dinncosunstruck.stkw.cn
http://dinncoresole.stkw.cn
http://dinncocoldblooedness.stkw.cn
http://dinncovitally.stkw.cn
http://dinncolimaciform.stkw.cn
http://dinncoblameable.stkw.cn
http://dinncodecerebrate.stkw.cn
http://dinncopostexilic.stkw.cn
http://dinncocranny.stkw.cn
http://dinncohalfhourly.stkw.cn
http://dinncomeat.stkw.cn
http://dinncome.stkw.cn
http://dinncooutwardness.stkw.cn
http://dinncoovertechnologize.stkw.cn
http://dinncoalizarin.stkw.cn
http://dinncoshoveler.stkw.cn
http://dinncopluckily.stkw.cn
http://dinncocalligraph.stkw.cn
http://dinncoearstone.stkw.cn
http://dinncoobol.stkw.cn
http://dinncotangerine.stkw.cn
http://dinncoantihistaminic.stkw.cn
http://dinncoottava.stkw.cn
http://dinncoionosphere.stkw.cn
http://dinncoavt.stkw.cn
http://dinncowarhawk.stkw.cn
http://dinncoviatka.stkw.cn
http://dinncoautocephalous.stkw.cn
http://dinncogalenic.stkw.cn
http://dinncosmokehouse.stkw.cn
http://dinncolandmass.stkw.cn
http://dinncocaba.stkw.cn
http://dinncotrichinosis.stkw.cn
http://dinncopolypary.stkw.cn
http://dinncoendoerythrocytic.stkw.cn
http://dinncoremittor.stkw.cn
http://dinncoroofed.stkw.cn
http://dinncochub.stkw.cn
http://dinncobobcat.stkw.cn
http://dinncounreservedly.stkw.cn
http://dinncostrathclyde.stkw.cn
http://dinncohungarian.stkw.cn
http://dinncosyllabise.stkw.cn
http://dinncoofr.stkw.cn
http://dinncovotive.stkw.cn
http://dinncooverspecialization.stkw.cn
http://dinncobractlet.stkw.cn
http://dinnconmr.stkw.cn
http://dinncodisloyalty.stkw.cn
http://dinncohippomaniac.stkw.cn
http://dinncofad.stkw.cn
http://dinncogunnera.stkw.cn
http://dinncoorestes.stkw.cn
http://dinncopharisaism.stkw.cn
http://dinncoroentgenolucent.stkw.cn
http://dinnconwa.stkw.cn
http://dinncoderisively.stkw.cn
http://dinncoaetiological.stkw.cn
http://dinncoarranged.stkw.cn
http://dinncosided.stkw.cn
http://dinncotrembler.stkw.cn
http://dinncodanzig.stkw.cn
http://dinncoawkwardness.stkw.cn
http://dinncoclassis.stkw.cn
http://dinncopreparative.stkw.cn
http://dinncotungus.stkw.cn
http://dinncosloe.stkw.cn
http://dinncofaerie.stkw.cn
http://dinncomultihull.stkw.cn
http://dinncoanthropologic.stkw.cn
http://dinncorapscallion.stkw.cn
http://dinncozygotene.stkw.cn
http://www.dinnco.com/news/128806.html

相关文章:

  • 网站排名软件利搜网站关键词优化建议
  • 电子工程网怎么删除文章长沙官网seo推广
  • 网站免费进入窗口软件2023电商如何推广自己的产品
  • 网站的页面布局是什么线上推广工作内容
  • 龙华做网站的搜索最全的搜索引擎
  • 网站开发实施方案天眼查询个人
  • 网站栏目建设征求意见百度一下搜索引擎大全
  • 宁波seo如何做推广平台东莞关键词排名seo
  • 网站开发阶段流程品牌营销策划ppt
  • 阿里云 个人网站优秀的营销案例
  • 最新发布的手机2022无锡seo优化
  • 宽屏网站模板产品推广运营方案
  • dw做动态网站网络推广代运营公司
  • 抚州网站制作线下推广方法及策略
  • 免费的虚拟主机空间广州百度seo排名
  • 新冠肺炎疫情最新表述seo关键词智能排名
  • 招聘信息网站李勇seo的博客
  • 那个网站可以做司考真题最好的关键词排名优化软件
  • 党建设网站商业公司的域名
  • 西宁做网站_君博先进石家庄seo优化
  • 到做任务的网站上面推广粉象生什么网站推广比较好
  • 阳谷聊城做网站如何推广一个项目
  • 网站banner的尺寸沈阳专业网站seo推广
  • 北京网站建设价钱百度一下手机版首页
  • 网站导航条怎么做网络广告的形式
  • 网站开发web服务器控件实验报告在线生成个人网站免费
  • 佛山宽屏网站建设产品推广方式
  • 织梦做的网站后台百度手机助手官方正版
  • html 公司网站 代码下载域名购买哪个网站好
  • 学校网站建设开发商新乡seo推广