pytest.ini 文件说明

pytest.ini 文件是用于配置 pytest 测试用例运行规则的文件。pytest.ini 配置文件支持的参数有以下几类:

  • 匹配测试文件和测试函数的过滤参数
  • 测试用例执行参数
  • 测试报告输出参数
  • 临时文件及路径参数
  • 插件参数

以下是一些常见的 pytest.ini 配置参数及其用法示例:

匹配测试文件和测试函数的过滤参数:

  • python_files: 用于匹配测试文件的文件名规则,通常测试文件名以 test_ 开头或者以 _test 结尾,中间部分为数字、字母或下划线。

示例:python_files = tests/*.py

  • python_functions: 用于匹配测试用例函数的命名规则,通常测试用例函数名以 test_ 开头。

示例:python_functions = test_*

测试用例执行参数:

  • addopts: 用于添加 pytest 命令行选项,如 -v 表示输出详细的测试用例信息。

示例:addopts = --verbose

测试报告输出参数:

  • junit_family: 指定生成 JUnit 风格的测试报告。

示例:junit_family = xunit2

临时文件及路径参数:

  • cache_dir: 指定 pytest 的缓存目录。

示例:cache_dir = .pytest_cache

插件参数:

  • pytester_example_dir: 指定 pytest 插件的示例目录。

示例:pytester_example_dir = examples

更多 pytest.ini 参数详情及配置示例,请参考官方文档:https://docs.pytest.org/en/latest/reference.html#ini-options-summary。

例如:

ini 复制代码
[pytest]
python_files = test_*.py *_test.py
python_functions = test_*
addopts = --verbose
norecursedirs = conf report
cache_dir = .pytest_cache
 
相关推荐
2301_7644413324 分钟前
使用python构建的应急物资代储博弈模型
开发语言·python·算法
喏喏心1 小时前
深度强化学习:价值迭代与Bellman方程实践
人工智能·python·学习·机器学习
小白勇闯网安圈1 小时前
supersqli、web2、fileclude、Web_python_template_injection
python·网络安全·web
用户8356290780511 小时前
从一维到二维:用Spire.XLS轻松将Python列表导出到Excel
后端·python
l木本I2 小时前
uv 技术详解
人工智能·python·深度学习·机器学习·uv
宁大小白2 小时前
pythonstudy Day31
python·机器学习
江上鹤.1482 小时前
Day34模块和库的导入
python
我爱鸢尾花2 小时前
第十四章聚类方法理论及Python实现
大数据·python·机器学习·数据挖掘·数据分析·聚类
言之。3 小时前
Dropbear远程连接
python
dhdjjsjs4 小时前
Day34 PythonStudy
python