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】

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

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

相关推荐
一 乐3 分钟前
高校评教|基于SpringBoot+vue高校学生评教系统 (源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·学习
是一个Bug6 分钟前
Spring事件监听器在电商订单系统中的应用
java·python·spring
解局易否结局9 分钟前
SecretFlow 社区MOOC学习笔记
学习
shangjian00723 分钟前
Python基础-闭包和装饰器
开发语言·python
三维空间35 分钟前
如何在Python多进程中避免死锁问题?
python
冤大头编程之路37 分钟前
Python并发编程实操教程:多线程/多进程/异步全解析
python
dhdjjsjs1 小时前
Day30 Python Study
开发语言·前端·python
qq_485668991 小时前
前端基础入门学习
前端·学习
子夜江寒1 小时前
HTML 基础知识
前端·学习·html
Eric.Lee20211 小时前
mujoco构建无物理约束的几何体运动
python·物理引擎·mujoco·物理模型仿真