Skip to main content

Generate pytest tests from captured fetch/XHR traffic via mitmproxy

Project description

Smoke-Test-Recorder

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

项目结构

auto-pytest-generator/
│
├── src/
│   └── auto_pytest_generator/
│       ├── __init__.py
│       ├── main.py             # CLI入口和mitmproxy启动逻辑与Filter插件
│       ├── addon.py              # pytest代码生成插件
│       └── 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 run apg --url-prefix http://1.2.3.4:5678/
  • 配置浏览器代理到apg代理服务
  • 访问 http://mitm.it 检查是否代理成功
  • 开始在客户端操作,用例被生成在./generated_tests/
  • 拷贝所有*.py文件到测试用例运行环境(依赖pytest,requests)

Project details


Download files

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

Source Distribution

auto_pytest_generator-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

auto_pytest_generator-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file auto_pytest_generator-0.1.0.tar.gz.

File metadata

File hashes

Hashes for auto_pytest_generator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 878ad2c60666d230ce4c8fd7122a5bdc6bcd8c6075683bddeaf754abd4a1163d
MD5 038c1c7d841b44a39f32c169bcfc6ef7
BLAKE2b-256 f4be70c6754254e18299948313faf4654fd88f1ba40b8138055530a25fcd20dd

See more details on using hashes here.

File details

Details for the file auto_pytest_generator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for auto_pytest_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 151838cf0df902b8d5e0d9c86ae6b657b841e3247d95f58105ba1a3be5316216
MD5 0cf856adaad350871c294b4e4194f371
BLAKE2b-256 1d95cb4edc0099dc3e38eec94dda26e8979ec2ab10f02d4abbb35cc63b4919b7

See more details on using hashes here.

Supported by

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