首页 > 图灵资讯 > 技术篇>正文

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

2023-06-25 14:29:22

前言

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

创建项目demo结构

执行以下命令

pytest --start-project

运行日志

(venv) D:\demo\untitled_start>pytest --start-projectcreate ini file: D:\demo\untitled_start\pytest.inicreate config file: D:\demo\untitled_start\config.pycreate file: D:\demo\untitled_start\case_democreate yaml file: D:\demo\untitled_start\case_demo\test_get.ymlcreate yaml file: D:\demo\untitled_start\case_demo\test_post.ymlcreate yaml file: D:\demo\untitled_start\case_demo\test_extract.yml

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

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

test_extract.yml 内容

config:  name: 参数关联-用例a提取结果给到用例btest_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 = trueenv = test

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

pytest

执行结果

pytest + yaml 框架 -39.新增--start-project命令快速创建项目demo结构_用例_02

上一篇 人工智能产品经理读书笔记1
下一篇 快速查看日志的方法

文章素材均来源于网络,如有侵权,请联系管理员删除。