day83 pytest测试用例执行顺序
学习日期:20241129
学习目标:http定义及实战 -- pytest测试用例执行顺序
学习笔记:
测试用例执行顺序
-
- 默认执行顺序
- 使用pytest-ordering自定义顺序
pytest+requests练习
import requests
def test_mobile():
print("测试手机归属地get请求")
r = requests.get('http://api.binstd.com/shouji/query',
params={"shouji": "13456755448", "appkey": "0c818521d38759e1"})
print(r.status_code)
assert r.status_code == 200
result = r.json()
assert result['status'] == 0
assert result['msg'] == "ok"
assert result['result']["shouji"] == "13456755448"
assert result['result']["province"] == "浙江"
assert result['result']["city"] == "杭州"
assert result['result']["company"] == "中国移动"
assert result['result']["cardtype"] is None
assert result['result']["areacode"] == "0571"
def test_mobile_post():
params = {
"shouji": "13456755448",
"appkey": "0c818521d38759e1"
}
r = requests.post('https://api.binstd.com/shouji/query', params=params)
assert r.status_code == 200
result = r.json()
assert result['status'] == 0
assert result['msg'] == "ok"
assert result['result']["shouji"] == "13456755448"
assert result['result']["province"] == "浙江"
assert result['result']["city"] == "杭州"
assert result['result']["company"] == "中国移动"
assert result['result']["cardtype"] is None
assert result['result']["areacode"] == "0571"
总结
- 测试用例默认从后往前执行顺序
- 使用pytest-ordering自定义顺序