接口测试demo:https://httpbin.testing-studio.com/
官网文档:https://docs.python-requests.org/en/master/
编写一个简单的接口测试用例
1.创建python文件
2.File | Settings | Project: xx| Python Interpreter中引入request、pytest包
3.设置运行方式为pytest,File | Settings | Tools | Python Integrated Tools
4.开始写
import requests
class TestDemo: // 运行pytest文件,类名需要以Test命名,python文件前面加上test_
def test_get(self):
r = requests.get('https://httpbin.testing-studio.com/get')
print(r.next) //返回的内容是什么
print(r.json()) //打印返回json
print(r.status_code) //打印状态码
assert r.status_code==200 //断言
5.右键或点击绿色执行按钮,以pytest方式执行代码,控制台打印py执行结果

或者terminal窗口以命令行方式运行py,pytest+文件名

网友评论