pytest配置文件ini

总结 pytest.ini
- 修改用例的命名规则
- 配置日志格式,比代码配置更方便
- 指定执行目录
- 排除搜索目录
- 添加标签,防止运行过程报警告错误
- 添加默认参数
注意:windows下要去掉所有的中文,不然会出现编码问题
报错:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xaa in position 15
pytest.ini
[pytest]
;下面为配置不同运行规则
;run cases files with check_* and test_* titles,执行check_开头和 test_开头的所有的文件,后面一定要加*
python_files = check_* test_*
;run test class with Check* and Test* titles,执行所有的以Test和Check开头的类
python_classes = Test* Check*
;run test function with check_* and test_* titles,执行所有以test_和check_开头的方法
python_functions= test_* check_*
;addopts设置默认运行pytest命令时带上的参数
;addopts = -vs
;设置执行的路径
testpaths = bilibili baidu
;忽略某些文件夹/目录
norecursedirs = result logs datas test_demo*
;日志设置
;日志开关 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

浙公网安备 33010602011771号