import unittest from ddt import ddt, data, unpack import requests test_data = [['xs', 'xs01', 'xs02','xs03'], ['cs', 'cs01', 'cs02', 'cs03'], ['cr', 'cr01', 'cr02', 'cr03']] @ddt class TestMath(unittest.TestCase): @classmethod def setUpClass(cls): pass @classmethod def tearDownClass(cls): pass def setUp(self): print('开始-------------') def tearDown(self): print('结束-------------') @data(*test_data) @unpack # 在“脱外套”之后,针对你拿到的每一条数据根据逗号进行拆分 def test_print_data(self, a, b,c,d): # 需要按拆出来的每条数据内的个数进行传参 response = requests.get("http://httpbin.org/get",params={a:b,c:d}) print(response.status_code) print(response.url) if __name__ == "__main__": unittest.main()
执行结果:
开始-------------
200
http://httpbin.org/get?xs=xs01&xs02=xs03
结束-------------
开始-------------
200
http://httpbin.org/get?cs=cs01&cs02=cs03
结束-------------
开始------------
200
http://httpbin.org/get?cr=cr01&cr02=cr03
结束-------------