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
 
相关推荐
站大爷IP3 分钟前
5个技巧写出专业Python代码:从新手到进阶的实用指南
python
hrrrrb22 分钟前
【Python】字符串
java·前端·python
大翻哥哥37 分钟前
Python 2025:低代码开发与自动化运维的新纪元
运维·python·低代码
Source.Liu1 小时前
【Pywinauto库】12.2 pywinauto.element_info 后端内部实施模块
windows·python·自动化
Source.Liu1 小时前
【Pywinauto库】12.1 pywinauto.backend 后端内部实施模块
开发语言·windows·python·自动化
用户8356290780511 小时前
用Python高效处理Excel数据:Excel数据读取指南
后端·python
我星期八休息1 小时前
深入理解跳表(Skip List):原理、实现与应用
开发语言·数据结构·人工智能·python·算法·list
蒋星熠2 小时前
如何在Anaconda中配置你的CUDA & Pytorch & cuNN环境(2025最新教程)
开发语言·人工智能·pytorch·python·深度学习·机器学习·ai
合作小小程序员小小店2 小时前
机器学习介绍
人工智能·python·机器学习·scikit-learn·安全威胁分析
JavaEdge在掘金2 小时前
掌握Spring IoC容器和Bean作用,轻松实现依赖注入!
python