pytest基于配置文件运行pytest
在pytest提供的终端运行测试用例的方式的基础上,pytest还支持使用配置文件来简化运行参数。可以通过pytest --help 查看pytest配置文件的名:pytest.ini \tox.ini\setup.cfg.CI持续集成(setup.cfg) git commit 配置文件一般保存在项目根目录下。
添加配置文件pytest.ini
[pytest] addopts =-s -v testpaths = ./ python_files = test_*.py python_classes = Test* python_functions = test_*
[pytest]:命名空间,表示以下选项属于pytest配置
addopts:运行参数
testpaths:匹配搜索测试文件的目录和路径
python_files:匹配搜索测试文件名格式
python_classes:匹配搜索测试类格式
python_functions:匹配搜索测试方法名格式
执行结果如下:
![](https://img2022.cnblogs.com/blog/2014081/202208/2014081-20220828220749980-592918878.png)