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

      

      

  • 相关阅读:
    Mac 升级后 Git报错处理
    iOS 进制转换(十进制转62进制)
    转:基于IOS上MDM技术相关资料整理及汇总
    NPM ERR! 403 403 Forbidden 问题处理
    Rxjs学习,结合angular(搁置,后续还会添加)
    如何快速关联/修改Git远程仓库地址
    VUE 路由守卫 next() / next({ ...to, replace: true }) / next(‘/‘) 说明
    chrome developer tools 的一個 bug
    IBM MQ 2035错误
    tp5 gateway 报错 stream_socket_client(): unable to connect to tcp://127.0.0.1:1236 (Connection refused)
  • 原文地址:https://www.cnblogs.com/lucylu/p/13522148.html
Copyright © 2011-2022 走看看