簡體   English   中英

如何在pytest.parametrize中訪問測試的索引

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM