pytest断言和取值(*)

进行一个断言:

import requests
def test_mobile():
    params = {
        "shouji": "18989490942",
        "appkey": "0c818521d38759e1"
    }

    r = requests.post('https://api.binstd.com/shouji/query', params=params)
    print(r.status_code)
    assert r.status_code == 200
    print(r.json())
    result = r.json()
    assert result['status'] == 0
    assert result['msg'] == 'ok'
    assert result['result']["shouji"] == '18989490942'
    assert result['result']['company'] == '中国电信'
    assert result['result']['province']==''
""" 响应结果:
    {    'status': 0,
         'msg': 'ok',
         'result':
             {'shouji': '18989490942',
              'province': '',
              'city': '',
              'company': '中国电信',
              'cardtype': None}
         }
"""

断言语法格式:

assert    a==b

响应取值语法格式:

响应变量名.[ ] [ ]  进行一个取值

 

posted @ 2024-02-08 17:16  贰零一八  阅读(16)  评论(0编辑  收藏  举报