You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用pytest命令仅运行parametrize中的单个或部分测试参数?

仅运行pytest parametrize中的单个参数测试

你之前的命令报错是因为pytest对参数化测试的节点ID格式要求用方括号包裹参数标识,而非双冒号。下面是两种可行的解决方法:

方法一:使用-k参数匹配参数名称

直接通过参数的函数名进行匹配,执行以下命令:

pytest test_plot_shap_values.py::tests_plot_shap_values -k "get_binary_data_and_with_many_category"

-k参数支持模糊匹配,只要字符串能唯一对应目标参数的测试用例即可。

方法二:通过完整节点ID运行

先执行命令查看所有参数化测试的节点ID:

pytest test_plot_shap_values.py::tests_plot_shap_values --collect-only

执行后会输出类似如下的测试用例列表:

<Function tests_plot_shap_values[get_binary_data_and_with_many_category]>
<Function tests_plot_shap_values[get_multiclass_data_and_with_many_category]>
<Function tests_plot_shap_values[get_binary_data_and_without_category]>
<Function tests_plot_shap_values[get_multiclass_data_and_without_category]>

复制目标测试用例的节点ID,运行对应命令:

pytest test_plot_shap_values.py::tests_plot_shap_values[get_binary_data_and_with_many_category]

内容的提问来源于stack exchange,提问作者Ozer Ozdal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 13:28:13