pytest 接口测试框架学习

python 复制代码
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 == 200def test_post_json(self):<br>    payload = {<br>        "level": 1,<br>        "name": "xuefeifei"<br>    }<br>    r = requests.post("https://httpbin.testing-studio.com/post", json=payload)<br>    print(r.json())<br>    assert r.json()["json"]["level"] == 1

使用pycharm

新建一个project, 进入preferences,添加 pytest,和requests


资料获取方法

【留言777】

各位想获取源码等教程资料的朋友请 点赞 + 评论 + 收藏 ,三连!

三连之后我会在评论区挨个私信发给你们~

相关推荐
AI小云6 分钟前
【Python与AI基础】Python编程基础:模块和包
人工智能·python
努力努力再努力wz20 分钟前
【C++进阶系列】:万字详解智能指针(附模拟实现的源码)
java·linux·c语言·开发语言·数据结构·c++·python
敲代码的嘎仔35 分钟前
JavaWeb零基础学习Day2——JS & Vue
java·开发语言·前端·javascript·数据结构·学习·算法
小蕾Java1 小时前
Python详细安装教程(附PyCharm使用)
开发语言·python·pycharm
Amy_au1 小时前
AWS Lambda 学习笔
学习·云计算·aws
weixin_307779131 小时前
使用AWS IAM和Python自动化权限策略分析与导出
开发语言·python·自动化·云计算·aws
惜月_treasure1 小时前
从零构建私域知识库问答机器人:Python 全栈实战(附完整源码)
开发语言·python·机器人
chennn122 小时前
c++相关学习
开发语言·c++·学习
哈里谢顿2 小时前
threading模块学习
python
mit6.8243 小时前
[VoiceRAG] Azure | 使用`azd`部署应用 | Dockerfile
python