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】

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

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

相关推荐
次旅行的库几秒前
【问渠哪得清如许-数据分析】学习笔记-下
数据库·笔记·sql·学习
万粉变现经纪人4 分钟前
如何解决 pip install cx_Oracle 报错 未找到 Oracle Instant Client 问题
数据库·python·mysql·oracle·pycharm·bug·pip
sw1213894 分钟前
使用Plotly创建交互式图表
jvm·数据库·python
2301_810160957 分钟前
如何为开源Python项目做贡献?
jvm·数据库·python
若惜8 分钟前
selenium自动化测试web自动化测试 框架封装Pom
前端·python·selenium
weixin_4577600014 分钟前
基于pytorch实现LPR模型车牌识别
人工智能·pytorch·python·深度学习·lpr
Dfreedom.16 分钟前
机器学习经典算法全景解析与演进脉络(监督学习篇)
人工智能·学习·算法·机器学习·监督学习
Zaly.16 分钟前
【Python刷题】LeetCode 3567 子矩阵的最小绝对差
python·leetcode·矩阵
sheji341619 分钟前
【开题答辩全过程】以 基于Android的奥运英语学习软件的设计与实现为例,包含答辩的问题和答案
学习
2501_9454235422 分钟前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python