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
 
相关推荐
小鸡吃米…几秒前
机器学习 - 精确率与召回率
人工智能·python·机器学习
sonrisa_9 分钟前
Python同一类不同方法中变量值的传递
开发语言·windows·python
逻极40 分钟前
OpenClaw「Clawdbot/Moltbot」 深入解析:核心架构深度剖析
python·ai·架构·agent·ai编程·moltbot·openclaw
sayang_shao42 分钟前
C++ ONNX Runtime 与 Python Ultralytics 库实现 YOLOv8 模型检测的区别
c++·python·yolo
曹牧43 分钟前
Java:强类型转换
开发语言·python
爱学习的阿磊1 小时前
Python入门:从零到一的第一个程序
jvm·数据库·python
naruto_lnq1 小时前
编写一个Python脚本自动下载壁纸
jvm·数据库·python
仟濹1 小时前
【Java加强】1 异常 | 打卡day1
java·开发语言·python
Dingdangcat861 小时前
基于RetinaNet的建筑表面缺陷检测与识别系统研究_2
python
袖清暮雨1 小时前
Python爬虫(Scrapy框架)
开发语言·爬虫·python·scrapy