pytest的init配置

pytest 的初始配置

[pytest]  ## [节]

pythonpath = .  ##  pythonpath:管理系统路径,是系统 import 的参考点
##  这里的.就是以ini文件所在根目录加入搜索路径

addopts = -vs --alluredir=./reports/temp --clean-alluredir  ## addopts:add options追加选项。每次运行 pytest,自动加上等号后面的命令参数
##  -vs:-v-s
## -v:显示每个测试用例名字和结果
##  -s:不捕获测试中的输出,直接显示在控制台
##  --alluredir=./reports/temp:指定 Allure 原始测试结果输出目录为 ./reports/temp。运行测试后会在这个目录生成 Allure 的 JSON/XML 等原始结果文件,要查看html报告通常还需要
## allure generate ./reports/temp -o ./reports/html --clean
## allure open ./reports/html
## --clean-alluredir:清空./reports/temp(每次运行前都要清空报告数据目录,因为allure的目录是增量写入,不清空,上次的结果会混进这次)

testpaths = ./testcase## 只输入 pytest,没有指定文件的默认目录

python_files = test_*.py
python_classes = Test*
python_functions = test_* ## python 默认收集规则就是这三条:test前缀或者后缀的文件;Test开头的类,test前缀的方法(函数)

markers =
    smoke: 冒烟用例
    regression: 回归用例 ## mark:自定义标记的注册(使用:@pytest.mark.*)
posted @ 2026-10-26 11:53  GJ504b  阅读(7)  评论(0)    收藏  举报