pytest命令用于测试pytest.mark.parametrize参数中的一个或多个参数是什么?

huangapple go评论54阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月5日 11:53:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403422.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定