zoukankan      html  css  js  c++  java
  • @pytest.mark.parametrize使用笔录

    1.实现多组合测试0-0、0-1、1-0、1-1

    测试数据:

    iphone_json = [{
        "devicePhonePojoList": [
    
            {
                "registrationId": "65ou4oadi7o7fuo",
                "mobile": ""
            }
        ]
    }, {
        "devicePhonePojoList": [
    
            {
                "registrationId": "65ou4oadi7o7fuo",
                "mobile": "18321793913"
            }
        ]
    }]
    
    testMobile = [[""],["18321793913"]]
    

     测试代码: 

    @pytest.mark.parametrize('mobile', testMobile)  # 输出
    @pytest.mark.parametrize('iphone', iphone_json)  # 输入
    def test_update_iphone(mobile, iphone): url = url_web + '/phone' headers = {"Content-Type": "application/json", "key": "2dbe655e88c80"} tel = RequestHandler() response = tel.visit(method='post', url=url, headers=headers, json=iphone) assert response.status_code == 200 logging.info("update iphone接口调用成功,status_code==200") GetNum = get_iphone() time.sleep(2) try: assert mobile == GetNum logging.info('update iphone成功') except Exception as e: logging.info('update的iphone,与get的iphone,不一致')

      

    运行结果:

    test_webapi.py::test_update_iphone[iphone0-mobile0]                                                        
    test_webapi.py::test_update_iphone[iphone1-mobile1]             
    test_webapi.py::test_update_iphone[iphone0-mobile1]                                                        
    test_webapi.py::test_update_iphone[iphone1-mobile0]                                                       
                                              
    

      

    2.确定的测试数据和输出结果验证

    测试数据:

    t1 = ({'devicePhonePojoList': [{'registrationId': '65ou4oadi7o7fuo', 'mobile': ''}]},  ['1'])
    t2 = ({'devicePhonePojoList': [{'registrationId': '65ou4oadi7o7fuo', 'mobile': '18321793913'}]}, ['18321793913'])  

    测试代码:

    @pytest.mark.parametrize('iphone,mobile',[t1,t2])
    def test_update_iphone(mobile, iphone):
        url = url_web + '/phone'
        headers = {"Content-Type": "application/json", "key": "2dbe655e88c80"}
        tel = RequestHandler()
        response = tel.visit(method='post', url=url, headers=headers, json=iphone)
        assert response.status_code == 200
        logging.info("update iphone接口调用成功,status_code==200")
        GetNum = get_iphone()
        time.sleep(2)
        try:
            assert mobile == GetNum
            logging.info('update iphone成功')
        except Exception as e:
            logging.info('update的iphone,与get的iphone,不一致')  

    运行结果:

    test_webapi.py::test_update_iphone[iphone0-mobile0] PASSED                                                              [ 50%]
    test_webapi.py::test_update_iphone[iphone1-mobile1] PASSED                                                              [100%]
    
    ====================================================== 2 passed in 4.28s ======================================================
    

      

      

  • 相关阅读:
    windows下Yarn安装与使用(两种方法)
    git配置公钥---解决码云出现git@gitee.com: Permission denied (publickey)
    npm使用国内镜像的两种方法
    【LeetCode】33. Search in Rotated Sorted Array (4 solutions)
    【LeetCode】83. Remove Duplicates from Sorted List
    【LeetCode】82. Remove Duplicates from Sorted List II
    【LeetCode】85. Maximal Rectangle
    【LeetCode】84. Largest Rectangle in Histogram
    【LeetCode】87. Scramble String
    【LeetCode】162. Find Peak Element (3 solutions)
  • 原文地址:https://www.cnblogs.com/lucylu/p/13522148.html
Copyright © 2011-2022 走看看