pytest參數化


#單個參數A
@pytest.mark.parametrize("A", [1, 2, 3, 4, 5])
def test_A(A):
    assert A > 3

#多個參數
@pytest.mark.parametrize("F,G,H",
                         ([(1,2,3),
                           (4,5,6),
                           (7,8,9)]))
def test_F(F,G,H):
    assert F+G>H

#多個參數換個寫法
@pytest.mark.parametrize("K,L,M",(
        pytest.param(1,2,3),
        pytest.param(4,5,6),
        pytest.param(7,8,9)))
def test_K(K,L,M):
    assert K+L>M

 

@pytest.mark.parametrize("I",[
    pytest.param([1,2,3]),
    pytest.param([4,5,6])])
def test_I(I):
    assert I

#定義一個id做標識
@pytest.mark.parametrize("J",[
    pytest.param([1,2,3],id="first case"),
    pytest.param([4,5,6],id="second case")])
def test_J(J):
    assert J

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM