python pytest mark.parametrize

雖然可以在測試函數內循環遍歷所有參數的可能性,但一旦失敗就終止了,即使try結果也比較南分析,所以可以使用pytest.mark.parametrize(argnames, argvalues)

# test_parametrize.py

@pytest.mark.parametrize('passwd',
                      ['123456',
                       'abcdefdfs',
                       'as52345fasdf4']) # 會執行3次
def test_passwd_length(passwd):
    assert len(passwd) >= 8

https://learning-pytest.readthedocs.io/zh/latest/doc/test-function/parametrize.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章