从HAR文件,Swagger接口文档自动生成API接口文件和pytest+allure测试用例
Project description
har2pytest
从 HAR 文件和 Swagger 文档生成 Python API 接口文件,并自动生成 pytest + allure 测试用例的工具。
安装
pip install -e .
验证安装:
har2pytest help
快速开始
1. 从 HAR 文件生成 API 文件
har2pytest api api_request.har
2. 从 Swagger 文档生成 API 文件
har2pytest swagger https://petstore.swagger.io/v2/api-docs
3. 生成测试用例
# 查询类参数化测试
har2pytest testcase api_request.har --pattern list_query --url /api/user/list
# 复杂场景流程测试
har2pytest testcase api_request.har --pattern complex_scenario --url /api/user/login
# 批量生成(无需 HAR 文件)
har2pytest testcase --pattern batch --api-files apis/mobile_application/_mobile_user_list.py
4. 查看 HAR 文件摘要
har2pytest summary api_request.har
详细文档
| 文档 | 说明 |
|---|---|
| API 文件生成 | 从 HAR / Swagger 生成 API 文件的详细说明 |
| HAR 文件解析 | HAR 解析规则与参数过滤 |
| Swagger 文档解析 | Swagger 文档获取与参数提取 |
| 测试用例生成模式 | list_query / complex_scenario / batch 三种模式详解 |
配置
在项目根目录创建 har2pytest_config.json 自定义配置。配置项详见 APIConfig 类(config.py)。
项目结构
har2pytest/
├── har2pytest/ # 核心代码
│ ├── __init__.py
│ ├── __main__.py # CLI 入口
│ ├── config.py # 配置管理 (APIConfig)
│ ├── har_parser.py # HAR 文件解析 (HARParser)
│ ├── har_generator.py # HAR → API 文件生成 (HARGenerator)
│ ├── api_generator.py # API 文件生成 (APIGenerator)
│ ├── swagger_handler.py # Swagger 文档处理 (SwaggerHandler)
│ ├── testcase_generator.py # 测试用例生成 (TestCaseGenerator)
│ └── utils.py # 工具函数
├── docs/ # 详细文档
├── tests/ # 单元测试
└── har2pytest_config.json.example # 配置示例
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file har2pytest-1.0.0.tar.gz.
File metadata
- Download URL: har2pytest-1.0.0.tar.gz
- Upload date:
- Size: 64.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd6cb500373ac34520549448d6359a0d1eeba5f1df3e0503463a10958b2b3dce
|
|
| MD5 |
442daea4ce6eed173d41f52f57bb1f2c
|
|
| BLAKE2b-256 |
5889a81a42b5395fb0fb721fcd7150f42693d5ab791886da14c094029c7738a5
|
Provenance
The following attestation bundles were made for har2pytest-1.0.0.tar.gz:
Publisher:
publish.yml on hewei198711/har2pytest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
har2pytest-1.0.0.tar.gz -
Subject digest:
dd6cb500373ac34520549448d6359a0d1eeba5f1df3e0503463a10958b2b3dce - Sigstore transparency entry: 1796564487
- Sigstore integration time:
-
Permalink:
hewei198711/har2pytest@81fd4c879678ed76f2554310e7ec66cc72597d9a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/hewei198711
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@81fd4c879678ed76f2554310e7ec66cc72597d9a -
Trigger Event:
push
-
Statement type:
File details
Details for the file har2pytest-1.0.0-py3-none-any.whl.
File metadata
- Download URL: har2pytest-1.0.0-py3-none-any.whl
- Upload date:
- Size: 43.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7abc3368d4252902c7c2312dae2894376a9e76b99548d6938d31e5494733665
|
|
| MD5 |
bd9235e2e125d8e0cefee623d597da8d
|
|
| BLAKE2b-256 |
1270d1f05b33d05ed1c1cc0090326d1fed71870852876880cb7b0f22de9f758e
|
Provenance
The following attestation bundles were made for har2pytest-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on hewei198711/har2pytest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
har2pytest-1.0.0-py3-none-any.whl -
Subject digest:
a7abc3368d4252902c7c2312dae2894376a9e76b99548d6938d31e5494733665 - Sigstore transparency entry: 1796564622
- Sigstore integration time:
-
Permalink:
hewei198711/har2pytest@81fd4c879678ed76f2554310e7ec66cc72597d9a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/hewei198711
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@81fd4c879678ed76f2554310e7ec66cc72597d9a -
Trigger Event:
push
-
Statement type: