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】

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

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

相关推荐
摸鱼仙人~16 分钟前
一文详解PyTorch DDP
人工智能·pytorch·python
超级种码16 分钟前
Java:JavaAgent技术(java.instrument和java.attach)
java·开发语言·python
少云清1 小时前
【接口测试】4_代码实现 _pytest框架
pytest·接口测试
Salt_07281 小时前
DAY44 简单 CNN
python·深度学习·神经网络·算法·机器学习·计算机视觉·cnn
Iridescent11211 小时前
Iridescent:Day35
python
a程序小傲1 小时前
阿里Java面试被问:.Java 8中Stream API的常用操作和性能考量
开发语言·windows·python
Asus.Blogs2 小时前
SSE + Resty + Goroutine + Channel 完整学习笔记
笔记·学习·golang
智航GIS2 小时前
2.3 运算符详解
开发语言·python
屋顶那猫2 小时前
使用pyinstaller打包pytest项目
python·pytest
web3.08889992 小时前
接入API-自动化批量获取淘宝商品详情数据
开发语言·python