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
 
相关推荐
萧鼎7 分钟前
深入解析 Python 的 Word 模板引擎:docxtpl 全面指南
开发语言·python·word
Yeats_Liao14 分钟前
昇腾910B与DeepSeek:国产算力与开源模型的架构适配分析
人工智能·python·深度学习·神经网络·机器学习·架构·开源
智航GIS16 分钟前
11.3 Pandas 模块功能概览
python·信息可视化·pandas
浩子智控16 分钟前
开源RPA选择
python·c#·软件工程
kszlgy18 分钟前
Day48 随机函数与广播机制
python
子午22 分钟前
【2026原创】昆虫识别系统~Python+深度学习+卷积算法+模型训练+人工智能
人工智能·python·深度学习
nju_spy29 分钟前
动手学强化学习上交张伟楠(一)导论 + 多臂老虎机 MAB(ε-greedy+上置信界+汤普森采样)
人工智能·python·强化学习·actor-critic·多臂老虎机·汤普森采样·探索与利用
tjjucheng31 分钟前
专业做小程序定制开发的企业
python
ACERT33334 分钟前
6.吴恩达机器学习——TensorFlow与激活函数
人工智能·python·机器学习