【pytest】参数化之多参数并行
适用情况:
- 参数1和参数2两个参数内容较多,需要文件读取;
- 参数1与参数2需要一一对应,作为每次测试case的输入(参数1[i],参数2[i])
1、参数数据文件:test.yml
failure: - "{ '标题' : '----' }" - "{ '正文' : '' }" failure_msg: - "不能有特殊字符" - "正文不能为空"
2、处理参数组合:get_data.py
failure = data['failure'] failure_msg = data['failure_msg'] failure_data = tuple(zip(failure, failure_msg)) # 合并为元组列表,便于参数化
3、测试用例输入:test_failed.py
@pytest.mark.parametrize('data,msg', failure_data) def test__f(self, data, msg): res = api.create(eval(data)) assert res.status_code == 200 assert not res.json()['success'] assert msg in res.text
python自动化 文章被收录于专栏
python写好pytest自动化的一些小妙招