pytest 接口测试框架学习
import requests class TestDemo: def test_get(self): r = requests.get("https://www.baidu.com/") print(r.status_code) assert r.status_code == 200 def test_query(self): payload = { "level": 1, "name": "xuefeifei" } r = requests.get("https://httpbin.testing-studio.com/get", params=payload) print(r.text) assert r.status_code == 200 def test_post_form(self): payload = { "level": 1, "name": "xuefeifei" } r = requests.post("https://httpbin.testing-studio.com/post", data=payload) print(r.text) assert r.status_code == 200
def test_post_json(self):
payload = {
"level": 1,
"name": "xuefeifei"
}
r = requests.post("https://httpbin.testing-studio.com/post", json=payload)
print(r.json())
assert r.json()["json"]["level"] == 1
使用pycharm
新建一个project, 进入preferences,添加 pytest,和requests