Skip to main content

Smoke-Test-Recorder

本工具旨在为0自动化覆盖的团队快速创建一套基于API流量的冒烟测试用例。它通过启动一个本地代理,捕获您在浏览器中与被测系统交互时产生的fetch/XHR流量,并自动生成基于requests的pytest测试代码。

项目结构

auto-pytest-generator/
│
├── src/
│   └── auto_pytest_generator/
│       ├── __init__.py
│       ├── main.py             # CLI入口和mitmproxy启动逻辑
│       ├── dispatcher_addon.py # 网络流量分发器,过滤静态文件流量,分发流量对应的pytest_generator实例
|       ├── pytest_generator.py # 使用jinja2生成pytest用例的模板逻辑
|       ├── response_refresher.py # 用于更新已有用例的response断言部分
│       └── templates/
│           └── pytest_template.jinja2 # Jinja2模板文件
│
├── tests/
│   └── ...                     # 工具自身的单元测试
│
├── .gitignore
├── pyproject.toml              # 项目打包和依赖管理
└── README.md                   # 使用文档

特点

  • 0配置启动:只需指定目标系统的URL前缀即可开始。
  • 自动化生成:在浏览器中操作,用例自动生成。
  • 基于真实数据断言:使用录制时的响应体做断言,无需依赖接口文档。
  • 易于集成:生成的代码是标准的pytest格式,可直接运行。

安装

# 推荐使用uv或pipx进行安装,以避免污染全局环境
uv tool install auto-pytest-generator

# 或者使用pip
pip install auto-pytest-generator

使用

  • 安装与更新

    • 安装:

      uv tool install auto-pytest-generator
      
    • 升级:

      uv tool upgrade auto-pytest-generator
      
  • 录制(生成用例)

    • 启动代理并录制前端产生的 GET/XHR 流量:

      uv run apg recorder --url-prefix http://1.2.3.4:5678/
      
    • 录制完成后,生成的测试用例通常位于 ./generated_tests/(或根据配置输出到指定目录)。

    • 配置浏览器代理到 apg 代理服务,访问 http://mitm.it 检查代理是否生效。

  • 更新 response 断言(refresh)

    • 使用已有用例回放并更新 response 断言:

      uv run apg response-refresh --origin-dir ./tests
      
    • 可选指定输出目录(默认会在项目下生成 refreshed_tests/):

      uv run apg response-refresh --origin-dir ./tests --target-dir ./refreshed_tests/
      
    • 输出示例目录: ./refreshed_tests/unchanged/ ./refreshed_tests/data_changed/ ./refreshed_tests/error/

  • 运行生成的用例

    • 将生成的 *.py 拷贝到测试运行环境(依赖 pytest, requests),使用 pytest 运行。

说明

  • 录制阶段建议在稳定的 test 环境进行,尽量保证测试数据可重置以提升用例稳定性。
  • refresh 阶段用于在新项目或后端变更时校验并自动更新断言,便于迁移验证。

Metadata

Release files for auto-pytest-generator 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for auto-pytest-generator 1.0.1
File Size Uploaded Provenance Actions
auto_pytest_generator-1.0.1.tar.gz 20.2 kB Without provenance Details for auto_pytest_generator-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for auto-pytest-generator 1.0.1
File Interpreter ABI Platform Actions
auto_pytest_generator-1.0.1-py3-none-any.whl Python 3 none any Details for auto_pytest_generator-1.0.1-py3-none-any.whl

Total release size: 39.6 kB

Release files / auto_pytest_generator-1.0.1.tar.gz

Download URL auto_pytest_generator-1.0.1.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
78e3f4d346d89f3813e18c1f387dacbef93ca8a550ca888b4d6f991cd88aabe5
BLAKE2b-256 checksum
How to use checksums
bebf00f2cf9d1da9a441dc604a5ec601f6a959f714b6df0c5cd3fef03e258651
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.15

Release files / auto_pytest_generator-1.0.1-py3-none-any.whl

Download URL auto_pytest_generator-1.0.1-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac1062696d7b9a369bcf67763d23d8caa3b58f6c477f471dc62889d810130848
BLAKE2b-256 checksum
How to use checksums
08ef9e71b583afc11a081159df7173b9094d5cb2a4aa680e9ae1096f5b3c303a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.15

Security for auto-pytest-generator 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page