英文:
What is the pytest command to test one or some of the pytest.mark.parametrize parameters?
问题
我尝试过pytest test_plot_shap_values.py::tests_plot_shap_values::get_binary_data_and_with_many_category
,但出现错误:未找到。
英文:
I have a unit test function similar to the following. How can I run pytest for only one of these parameters instead of 4 parameters?
@pytest.mark.parametrize("test_plot_shap_values", [get_binary_data_and_with_many_category,
get_multiclass_data_and_with_many_category,
get_binary_data_and_without_category,
get_multiclass_data_and_without_category
])
def tests_plot_shap_values(test_plot_shap_values):
...
...
I tried pytest test_plot_shap_values.py::tests_plot_shap_values::get_binary_data_and_with_many_category
but it gives me an ERROR: not found
答案1
得分: 1
你可以给参数添加标识符,然后使用 -k
参数来筛选它们。
在你的代码中:
@pytest.mark.parametrize("test_plot_shap_values", [get_binary_data_and_with_many_category,
get_multiclass_data_and_with_many_category,
get_binary_data_and_without_category,
get_multiclass_data_and_without_category
], ids=["id1", "id2", "id3", "id4"])
然后运行 pytest -k "tests_plot_shap_values and id2"
。
更多信息请查看 https://docs.pytest.org/en/7.1.x/example/parametrize.html#different-options-for-test-ids。
英文:
You can add ids to the parameters and then use the -k
argument to filter them.
In your code:
@pytest.mark.parametrize("test_plot_shap_values", [get_binary_data_and_with_many_category,
get_multiclass_data_and_with_many_category,
get_binary_data_and_without_category,
get_multiclass_data_and_without_category
], ids=["id1", "id2", "id3", "id4"])
Then pytest -k "tests_plot_shap_values and id2"
.
See more at https://docs.pytest.org/en/7.1.x/example/parametrize.html#different-options-for-test-ids
答案2
得分: 0
What about running it like this? pytest test_file_name.py::test_test_name[your_params]
即文件名,然后测试名称,然后是方括号中的参数值。
英文:
What about running it like this? pytest test_file_name.py::test_test_name[your_params]
i.e. file name, then test name, then param values in square brackets
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论