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
 
相关推荐
weixin_470740365 小时前
某算法的python执行汇编
汇编·python·算法
mit6.8247 小时前
[RestGPT] docs | RestBench评估 | 配置与环境
人工智能·python
Ice__Cai8 小时前
Flask 之 Cookie & Session 详解:用户状态管理
后端·python·flask·cookie·session
WSSWWWSSW10 小时前
Seaborn数据可视化实战:Seaborn时间序列可视化入门
python·信息可视化·数据分析·matplotlib·seaborn
云天徽上10 小时前
【数据可视化-96】使用 Pyecharts 绘制主题河流图(ThemeRiver):步骤与数据组织形式
开发语言·python·信息可视化·数据分析·pyecharts
codeyanwu11 小时前
nanoGPT 部署
python·深度学习·机器学习
quaer12 小时前
print(2 ** 3)
开发语言·python
翔云12345612 小时前
Python 中 SQLAlchemy 和 MySQLdb 的关系
数据库·python·mysql
三婶儿13 小时前
在没有客户端的客户环境下,如何用 Python 一键执行 MySQL 与达梦数据库 SQL
运维·后端·python