pytest + yaml 框架 - 新增--start-project命令快速创建项目demo结构

前言

新增 --start-project 命令, 帮助初学者快速创建项目 demo 结构, 并自动创建几个简单的用例。
创建项目demo结构

执行以下命令

pytest --start-project

运行日志

(venv) D:\demo\untitled_start>pytest --start-project
create ini file: D:\demo\untitled_start\pytest.ini
create config file: D:\demo\untitled_start\config.py
create file: D:\demo\untitled_start\case_demo
create yaml file: D:\demo\untitled_start\case_demo\test_get.yml
create yaml file: D:\demo\untitled_start\case_demo\test_post.yml
create yaml file: D:\demo\untitled_start\case_demo\test_extract.yml

执行完成会自动生成以下文件

test_extract.yml 内容

config:
  name: 参数关联-用例a提取结果给到用例b

test_a:
  name: extract提取结果
  request:
    method: POST
    url: /post
    json:
      username: test
      password: "123456"
  extract:
      url:  body.url
  validate:
  - eq: [status_code, 200]
  - eq: [headers.Server, gunicorn/19.9.0]
  - eq: [$..username, test]
  - eq: [body.json.username, test]

test_b:
  name: 引用上个接口返回
  request:
    method: GET
    url: http://httpbin.org/get
    headers:
      url: ${url}
  validate:
  - eq: [status_code, 200]

自动创建 pytest.ini 文件,并添加 2 个配置参数

[pytest]
log_cli = true
env = test

看到项目结构生成后,仅需执行 pytest 命令即可运行用例

pytest

执行结果

后:下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】

整套资料获取

猜你喜欢

转载自blog.csdn.net/wx17343624830/article/details/131287981