![](/img/trans.png)
[英]How to pass name of method in pytest.parametrize for executing them in test?
[英]how to access index of the test in pytest.parametrize
這些裝飾器進行6個測試:
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
@pytest.mark.parametrize("z", [4, 5])
如何在測試體內檢查pytest以獲取當前索引或測試的某些ID?
好的,我找到了:
@pytest.mark.parametrize("x", [pytest.param(0, id="first_test"), 1])
@pytest.mark.parametrize("y", [2, 3])
@pytest.mark.parametrize("z", [4, 5])
def test_it(request, x, y, z):
if request.node.nodename == "test_it[first_test]":
# something special
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.