pytest.ini


1.存放位置

放在工程根目录下面

2.编码

如果有中文内容(注释也包括),需要另存为为ANSI,要不然会报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 26: illegal multibyte sequence

,要不然就直接全英文

3.内容

[pytest]
# 命令行参数
#-s 用例里面 print/logging 输出都打印
#-x 用例遇见失败就停止执行, -x 参数
#-v 用例执行详情展示
addopts = -vs --alluredir=./report/data
#addopts = -v --reruns=1 --count=2 --html=reports.html --self-contained-html -n=auto

# 测试用例的路径
testpaths = test_case

#更改测试用例收集规则,pytest默认的测试用例收集规则:
#   文件名以 test_*.py 文件和 *_test.py
#   以  test_ 开头的函数
#   以  Test 开头的类,不能包含 __init__ 方法
#   以  test_ 开头的类里面的方法
#模块的命名规则 xx.py
python_files = test_*  *_test  test*
#类名的命名规则 Xxx
python_classes = Test*   test*
#方法的命名规则 **
python_functions = test_*  test*

#pytest收集测试用例时,会递归遍历所有子目录,包括某些你明知道没必要遍历的目录,可以使用 norecursedirs 参数简化 pytest 的搜索工作
norecursedirs = .* common config data log report utils

#是否打开日志记录功能
log_cli=1
; 以下为日志格式,输出到文件/控制台
;log_cli_level = DEBUG
;log_cli_date_format = %Y-%m-%d %H:%M:%S
;log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s:%(message)s)
;log_file = ./logs/DMTest.log
;log_file_level = DEBUG
;log_file_date_format = %Y-%m-%d %H:%M:%S
;log_file_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s:%(message)s)
# 标记参数,赋值方式为 key:value 
markers =
     smoke:冒烟测试
     login:登录
# 禁用xpass xfail_strict = true #插件使用 #required_plugins