zoukankan      html  css  js  c++  java
  • 自动化框架——PO设计模式自学——参数化配置——接口——简单get方法参数化示例

    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
    结束-------------

  • 相关阅读:
    python 安装与pip安装
    使用通配符来解决数据1和11、12/13/14的问题
    数据库中一行变多行,拆分数据
    15-哈希表 HashTable
    13-自平衡二分搜索树 AVLTree
    12-并查集 UnionFind
    11-字典树 Trie
    10-线段树 Segment Tree
    09-堆 Heap(最大堆)
    08-映射 Map
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12650868.html
Copyright © 2011-2022 走看看