pytest之参数化

风流意气都作罢 提交于 2019-12-18 04:38:56

格式 @pytest.mark.parametrize(variable,[value])

可以参考官方文档http://doc.pytest.org/en/latest/example/parametrize.html

@pytest.mark.parametrize(
    "example_input,expectation",
    [
        (3, does_not_raise()),
        (2, does_not_raise()),
        (1, does_not_raise()),
        (0, pytest.raises(ZeroDivisionError)),
    ],
)
def test_division(example_input, expectation):
    """Test how much I know division."""
    with expectation:
        assert (6 / example_input) is not None

这样,执行的时候,循环去读取每个tuplue的对应值

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!