赞
踩
下面列出的参数和功能涵盖了 pytest
中一些常用的选项,但 pytest
还有许多其他参数和功能。以下是一些补充的 pytest
命令行参数和功能:
测试配置
--confcutdir=<path>
: 只加载指定目录及其子目录中的配置文件。例如 --confcutdir=src
。--rootdir=<path>
: 设置根目录,这会影响 pytest
查找配置文件的方式。例如 --rootdir=tests
。插件相关
--disable-warnings
: 禁用警告输出。--version
: 显示 pytest
的版本信息。--help
: 显示所有可用的命令行参数和选项的帮助信息。参数化
--tb=<style>
: 设置 traceback 样式,short
、long
、line
和 no
。--trace
: 使用 Python 的调试器 pdb
调试失败的测试。插件管理
--plugins
: 显示已安装的插件及其版本信息。--maxfail=<num>
: 在失败的测试数达到 <num>
后停止测试(如之前所述)。性能和并行
--slow
: 可以与自定义标记结合使用,用于运行标记为 slow
的测试。--numprocesses=<num>
: 与 pytest-xdist
插件结合使用,指定并行测试进程的数量。例如 --numprocesses=4
。测试运行
--disable-warnings
: 禁用警告信息的输出。--reruns=<num>
: 失败的测试用例重新执行 <num>
次。需要安装 pytest-rerunfailures
插件。例如 --reruns=2
。下面是一个更复杂的示例命令,结合了多种选项:
pytest test_demo.py --count=3 --html=report.html --log-cli-level=INFO --maxfail=2 --disable-warnings --tb=short -n 4
这个命令:
test_demo.py
中的所有测试用例,每个用例执行 3 次。report.html
。INFO
。short
风格的 traceback。pytest-xdist
插件)。pytest
的功能非常丰富,具体使用哪些参数可以根据你的测试需求来选择。你可以使用 pytest --help
命令查看所有可用的参数和选项。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。