软件测试学习笔记丨Pytest配置文件(pytest.ini)

本文详细介绍了pytest配置文件pytest.ini的高级功能,包括修改命名规则、配置日志、指定执行路径、排除目录、添加标签和默认参数,以及如何利用它来优化测试流程和管理警告错误。
摘要由CSDN通过智能技术生成

本文转自测试人社区,原文链接:https://ceshiren.com/t/topic/30139

pytest配置文件 进阶

  • pytest.ini是什么
    1、pytest.ini是pytest的配置文件
    2、pytest.ini可以修改pytest的默认行为
    3、pytest.ini文件中内容(包括注释)不能使用任何中文符号,包括汉字、空格、引号、冒号等等
  • 用途
    1、修改用例的命名规则
    2、配置日志格式,比代码配置更方便
    3、添加标签,防止运行过程报警告错误
    4、指定执行目录
    5、排除搜索目录

pytest配置-改变运行规则
1、执行check_开头和 test_开头的所有的文件,后面一定要加*

python_files = check_* test_*

2、执行所有的以Test和Check开头的类

python_classes = Test* Check*

3、执行所有以test_和check_开头的方法

python_functions = test_* check_*

  • pytest配置-添加默认参数

addopts = -v -s --alluredir = ./results

  • pytest配置- 指定/忽略执行目录
    设置执行的路径

testpaths = bilibili baidu

  • 忽略某些文件夹/目录

norecursedirs = result logs datas test_demo*

  • pytest配置-日志

[pytest]
;日志开关 true false
log_cli = true
;日志级别
log_cli_level = info
;打印详细日志,相当于命令行加 -vs
addopts = --capture=no
;日志格式
log_cli_format = %(asctime)s [%(levelname)s] %(message)s (%(filename)s:%(lineno)s)
;日志时间格式
log_cli_date_format = %Y-%m-%d %H:%M:%S
;日志文件位置
log_file = ./log/test.log
;日志文件等级
log_file_level = info
;日志文件格式
log_file_format = %(asctime)s [%(levelname)s] %(message)s (%(filename)s:%(lineno)s)
;日志文件日期格式
log_file_date_format = %Y-%m-%d %H:%M:%S

  • 总结pytest.ini
    1、修改用例的命名规则
    2、配置日志格式,比代码配置更方便
    3、指定执行目录
    4、排除搜索目录
    5、添加标签,防止运行过程报警告错误
    6、添加默认参数

获取更多软件测试知识

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值