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

      

      

  • 相关阅读:
    用python抓取百度指数 以及 用cxfreeze打包的经验
    selenium中send_keys的使用
    python之文件调用
    学习python之selenium
    学习python图像识别
    解决方案: 运行ugarchroll,报错Error in try(.C("c_qstd", p = as.double(p), mu = as.double(mu), sigma = as.double(sigma), : NA/NaN/Inf in foreign function call (arg 3)
    int 转 const char*
    均值,方差,协方差,协方差矩阵,特征值,特征向量
    OpenCv 图片上添加汉字
    OpenCV获取与设置像素点的值的几个方法
  • 原文地址:https://www.cnblogs.com/lucylu/p/13522148.html
Copyright © 2020-2023  润新知