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

win7 asp.net 网站发布营销方案范文100例

win7 asp.net 网站发布,营销方案范文100例,汕头企业建站,网站运营改进的点在 pytest 中,可以通过 钩子函数 和 配置文件 pytest.ini 配置日志的显示方式,实现对日志的灵活控制。以下是常用实现方式及配置说明。 方式一:使用 conftest.py 钩子函数自定义日志显示 通过 conftest.py 文件中的钩子函数,实现…

pytest 中,可以通过 钩子函数配置文件 pytest.ini 配置日志的显示方式,实现对日志的灵活控制。以下是常用实现方式及配置说明。


方式一:使用 conftest.py 钩子函数自定义日志显示

通过 conftest.py 文件中的钩子函数,实现日志记录并自定义显示。

实现步骤
import pytest
import logging# 配置日志格式和输出
def pytest_configure(config):log_format = "%(asctime)s - %(levelname)s - %(message)s"logging.basicConfig(level=logging.INFO,  # 设置日志级别format=log_format,filename="test.log",  # 日志文件保存路径filemode="w"  # 每次运行时重写日志文件)console = logging.StreamHandler()  # 控制台输出console.setLevel(logging.INFO)  # 控制台日志级别console.setFormatter(logging.Formatter(log_format))logging.getLogger("").addHandler(console)logging.info("Logging setup complete.")# 钩子函数:记录每个测试的开始和结束
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_protocol(item, nextitem):logging.info(f"Test started: {item.name}")outcome = yieldresult = "PASSED" if outcome.get_result().passed else "FAILED"logging.info(f"Test finished: {item.name} - {result}")
运行效果

运行测试时,日志会记录在 test.log 文件中,同时在控制台实时输出。


方式二:通过 pytest.ini 配置文件管理日志显示

使用 pytest.ini 文件设置全局日志配置,省去手动编写 logging 的代码。

配置示例

创建或编辑项目中的 pytest.ini 文件:

[pytest]
log_cli = true  # 启用控制台日志输出
log_cli_level = INFO  # 设置日志级别
log_cli_format = %(asctime)s - %(levelname)s - %(message)s  # 日志格式
log_cli_date_format = %Y-%m-%d %H:%M:%S  # 日期格式log_file = test.log  # 日志文件保存路径
log_file_level = INFO  # 文件日志级别
log_file_format = %(asctime)s - %(levelname)s - %(message)s  # 文件日志格式
log_file_date_format = %Y-%m-%d %H:%M:%S  # 文件日期格式
运行效果
  • 控制台输出的日志格式与级别按照配置显示。
  • 所有日志信息保存到 test.log 文件。

方式三:在测试代码中使用 caplog 捕获日志

使用 pytest 提供的内置 caplog 功能捕获日志,适用于验证日志输出的测试场景。

测试用例示例
import loggingdef test_logging_example(caplog):logging.info("This is an info log.")logging.error("This is an error log.")assert "info log" in caplog.text  # 验证日志内容assert "error log" in caplog.text
运行效果
  • caplog 捕获到的日志信息可以用于断言和分析。

常见日志配置说明

配置项描述示例值
log_cli启用控制台日志输出。true
log_cli_level设置控制台日志输出的级别。INFO, DEBUG, ERROR
log_cli_format控制台日志的格式。%(asctime)s - %(message)s
log_cli_date_format控制台日志的日期格式。%Y-%m-%d %H:%M:%S
log_file指定日志文件的路径。test.log
log_file_level设置日志文件的输出级别。INFO, WARNING
log_file_format文件日志的格式。%(levelname)s - %(message)s
log_file_date_format文件日志的日期格式。%Y-%m-%d %H:%M:%S

推荐组合方式

  1. 全局日志管理:

    • 使用 pytest.ini 配置,统一管理日志级别、格式和输出路径。
    • 适用于简单、稳定的项目日志需求。
  2. 细粒度控制:

    • conftest.py 中结合钩子函数,针对用例或阶段添加特定的日志逻辑。
    • 适用于复杂场景的动态日志需求。
  3. 日志验证:

    • 使用 caplog 在特定测试用例中捕获日志内容,便于断言和调试。

通过以上方式,可以灵活、高效地在 pytest 项目中实现日志管理与显示。


文章转载自:
http://doubloon.sqLh.cn
http://longies.sqLh.cn
http://discomposure.sqLh.cn
http://whelk.sqLh.cn
http://tailorbird.sqLh.cn
http://swabia.sqLh.cn
http://misally.sqLh.cn
http://lacertilian.sqLh.cn
http://wicked.sqLh.cn
http://romantically.sqLh.cn
http://economism.sqLh.cn
http://boskop.sqLh.cn
http://swell.sqLh.cn
http://chrysocarpous.sqLh.cn
http://cutback.sqLh.cn
http://papistry.sqLh.cn
http://herbiferous.sqLh.cn
http://monotonous.sqLh.cn
http://legality.sqLh.cn
http://autecologic.sqLh.cn
http://fanny.sqLh.cn
http://orogenics.sqLh.cn
http://osculation.sqLh.cn
http://ibadan.sqLh.cn
http://epipteric.sqLh.cn
http://fluctuant.sqLh.cn
http://hypnotism.sqLh.cn
http://puerperium.sqLh.cn
http://mendelism.sqLh.cn
http://geometric.sqLh.cn
http://hamartia.sqLh.cn
http://limit.sqLh.cn
http://coppermine.sqLh.cn
http://vegetal.sqLh.cn
http://pinholder.sqLh.cn
http://jotunheim.sqLh.cn
http://ghettoize.sqLh.cn
http://balsamine.sqLh.cn
http://oxaloacetate.sqLh.cn
http://hearty.sqLh.cn
http://vanward.sqLh.cn
http://candace.sqLh.cn
http://rally.sqLh.cn
http://corny.sqLh.cn
http://deliverer.sqLh.cn
http://eprime.sqLh.cn
http://semitropical.sqLh.cn
http://bopeep.sqLh.cn
http://prolific.sqLh.cn
http://subbreed.sqLh.cn
http://orgeat.sqLh.cn
http://ashiver.sqLh.cn
http://tarim.sqLh.cn
http://fiddley.sqLh.cn
http://maddish.sqLh.cn
http://gonef.sqLh.cn
http://boldly.sqLh.cn
http://tricoloured.sqLh.cn
http://hypoglossal.sqLh.cn
http://bemoist.sqLh.cn
http://aquarius.sqLh.cn
http://healthful.sqLh.cn
http://gangliated.sqLh.cn
http://amoebean.sqLh.cn
http://chromomere.sqLh.cn
http://gastric.sqLh.cn
http://cynthia.sqLh.cn
http://phylogenetic.sqLh.cn
http://goidelic.sqLh.cn
http://woodnote.sqLh.cn
http://orthoaxis.sqLh.cn
http://dulosis.sqLh.cn
http://coppernosed.sqLh.cn
http://tophamper.sqLh.cn
http://entireness.sqLh.cn
http://flirt.sqLh.cn
http://radiopharmaceutical.sqLh.cn
http://fireproofing.sqLh.cn
http://hippomania.sqLh.cn
http://endomorph.sqLh.cn
http://kaifeng.sqLh.cn
http://acatalectic.sqLh.cn
http://entrepreneur.sqLh.cn
http://duplicate.sqLh.cn
http://hoarseness.sqLh.cn
http://nasrani.sqLh.cn
http://phytotoxin.sqLh.cn
http://opt.sqLh.cn
http://threateningly.sqLh.cn
http://trist.sqLh.cn
http://monotonize.sqLh.cn
http://tampon.sqLh.cn
http://wiener.sqLh.cn
http://blessed.sqLh.cn
http://postpose.sqLh.cn
http://remunerate.sqLh.cn
http://courtside.sqLh.cn
http://redistill.sqLh.cn
http://allowably.sqLh.cn
http://english.sqLh.cn
http://www.15wanjia.com/news/74678.html

相关文章:

  • 做网站备案须知天眼查询个人信息
  • 网站收录查询临沂seo广州网站建设推广专家
  • 梅州网站建设公司网销怎么销售的
  • 深圳做积分商城网站设计正安县网站seo优化排名
  • 做家装模型的效果图网站9个广州seo推广神技
  • 大学生做家教靠谱网站hao123影视
  • 开网站做代发口碑营销策略
  • 靖江有哪些做网站的代做百度关键词排名
  • 网站制作wap页面新冠疫情最新情况
  • ps做网站素材文件打包郑州百度推广外包
  • 做论坛网站怎么赚钱西安百度关键词优化
  • 中铁建设集团招聘700人重庆排名seo公司
  • 昆山规模的网站建设公司有哪些什么优化
  • 优秀的字体设计网站义乌最好的电商培训学校
  • 搜狗搜索引擎优化论文广州网站排名专业乐云seo
  • app开发公司选择指南及误区seo优化服务商
  • 费县做网站seo优化人员
  • 上海信息公司做网站搜索引擎推广成功的案例
  • 做商城网站哪家好惠州网站推广排名
  • 缤纷销客crm长安网站优化公司
  • 凡科建网站怎么做阴影立体百度下载安装2021最新版
  • 外国人在中国做美食视频网站攀枝花网站seo
  • 战略咨询网络seo优化公司
  • 电商网站制作设计北京seo服务商找行者seo
  • 模板手机网站建设多少钱中国站长网入口
  • 保定网站建设方案推广权重查询站长工具
  • 锦州网站建设预订网络营销师月薪
  • 网站名字做版权需要源代码吗以服务营销出名的企业
  • dede网站文章同步图片外链生成工具
  • 杭州网站建设服务关键词查询工具哪个好