httprunner 4.x学习 - 13. upload 文件上传

前言

requests 库里面上传文件会用到 requests_toolbelt, 可以很方便的解决 multipart/form-data 类型的文件上传相关接口。
HttpRunner4.x 集成了 requests_toolbelt,可以使用内置 upload 关键字来上传文件相关操作。

环境准备

需额外安装2个依赖包

pip install requests-toolbelt filetype

upload 上传文件

在项目根目录新建data目录,放需要传的文件

新建 test_up.yml

# 作者-上海悠悠 wx:283340479
# blog地址 https://www.cnblogs.com/yoyoketang/

config:
    name: file
teststeps:
-
    name: upload file
    request:
        url: http://124.70.221.221:8201/api/v1/upfile/
        method: POST
        upload:
            file: data/yoyo.jpg
            title: xxx
    validate:
        - eq: [body.code, 0]

使用 hrun 目录没问题

hrun test_up.yml

最新4.3.0 版本使用hrp run 无法上传成功

hrp run test_up.yml
posted @ 2023-05-11 08:11  上海-悠悠  阅读(427)  评论(1编辑  收藏  举报