Skip to main content

har2pytest

从 HAR 文件和 Swagger 文档生成 Python API 接口文件,并自动生成 pytest + allure 测试用例的工具。

安装

pip install har2pytest

验证安装:

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 文件生成
│   ├── api_generator.py     # API 文件生成 (APIGenerator)
│   ├── swagger_handler.py   # Swagger 文档处理 (SwaggerHandler)
│   ├── testcase_generator.py # 测试用例生成 (TestCaseGenerator)
│   └── utils.py             # 工具函数
├── docs/                    # 详细文档
├── tests/                   # 单元测试
│   └── har2pytest_config_test.json  # 测试配置示例
├── pyproject.toml           # 项目配置
└── mkdocs.yml               # 文档站点配置

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

har2pytest-1.1.0.tar.gz (67.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

har2pytest-1.1.0-py3-none-any.whl (46.2 kB view details)

Uploaded Python 3

File details

Details for the file har2pytest-1.1.0.tar.gz.

File metadata

  • Download URL: har2pytest-1.1.0.tar.gz
  • Upload date:
  • Size: 67.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for har2pytest-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a16894ddeda8e4d7fecff5b2ea3f41bb6d2e3b7dce437e15cd3499f607d837a6
MD5 0a299180488671b6b90ad20f9d415c5e
BLAKE2b-256 b1b5b66672df01e33eb6e9a40ca79b2e6126da55d6068a6b2837e88ae2a3baf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for har2pytest-1.1.0.tar.gz:

Publisher: publish.yml on hewei198711/har2pytest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file har2pytest-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: har2pytest-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for har2pytest-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b95ca763df3c0da66f1b9bf7eb449eddd80061e5c00665042927317d83f0f32e
MD5 f3d2c42aa1bf301c100f86af956876bd
BLAKE2b-256 fdb59fc73fd165f1e0b33be773a5805baf0f26a58a3ea4fc33e8b5be42139225

See more details on using hashes here.

Provenance

The following attestation bundles were made for har2pytest-1.1.0-py3-none-any.whl:

Publisher: publish.yml on hewei198711/har2pytest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page