如何用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
相关产品推荐
相关产品推荐

