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 ======================================================
    

      

      

  • 相关阅读:
    ...
    抛砖引玉,说平台概念
    杂想
    相机镜头简易擦拭篇
    优秀软件体验2
    牛人就在我的身边
    对魔时网做了一下了解
    来了兴致,试试django吧,呵呵
    SD2.0大会
    从《首届中国优秀软件创新大赛 寻找中国软件新星 》预测互联网的未来趋势
  • 原文地址:https://www.cnblogs.com/lucylu/p/13522148.html
Copyright © 2011-2022 走看看