pytest使用fixture傳遞測試數據

#使用usefixtures和在測試方法中添加fixture參數差很少,可是隻有後者才能用使用fix的返回值
@pytest.fixture()
def some_data():
    return (1,"a",None,{"b": 2})

def test_A(some_data):
    assert some_data[0]==1

def test_B(some_data):
    assert some_data[1]=="a"

def test_C(some_data):
    assert some_data[2] is None

def test_D(some_data):
    assert some_data[3]["b"]==2

#不能使用這種寫法傳值,會報錯
@pytest.mark.userfixtures("some_data")
def test_E():
    assert some_data[0] == 1
相關文章
相關標籤/搜索