【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自动化的一些小妙招

全部评论

相关推荐

牛客刘北:如果暑期实习是27届的话,你要晚一年才会毕业,企业为什么会等你呢?要搞清时间逻辑呀!27届现在实习只能是在暑假实习,这是日常实习,不是暑期实习。所以多去投日常实习吧,暑期实习肯定不会要你的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务