HAR2tavern
tavern 是一个pytest插件,用来进行接口自动化测试,通过YAML来描述和管理测试用例。 尽管YAML已经十分简洁,但是的接口数量很多时,创建YAML文件依然耗时。
本工具将通过抓包获取到的HAR文件,快速生成tavern所支持的YAML文件,实现快速进行接口自动化的目的。
当然,你也可以对生成的YAML进行修改,以实现复杂业务的测试。
安装
pip install har2tavern
使用
-
基本用法
>har2tavern file.harhar2 Output file: ./test_api_1.tavern.yaml Output file: ./test_api_2.tavern.yaml Output file: ./test_api_3.tavern.yaml Output file: ./test_api_4.tavern.yaml Output file: ./test_api_5.tavern.yaml Output file: ./test_api_6.tavern.yaml Output file: ./test_api_7.tavern.yaml Successfully generated 7 files
本命令将生成多个yaml格式的测试用例
-
更多参数
>har2pytest --help Usage: har2pytest [OPTIONS] HARFILE 根据har文件,生成yaml格式的接口自动化测试用例 Options: -H, --host TEXT 只为指定的host生成用例 -S, --single-file BOOLEAN 将用例合并到单个文件 --help Show this message and exit.
-
生成requests代码
>har2requests file.harhar2 import requests s = requests.Session() resp_1 = s.request( **{ "method": "POST", "url": "http://127.0.0.1:8000/todo", "headers": { "Host": "127.0.0.1:8000", "Connection": "keep-alive", "Accept": "application/json, text/plain, */*", "Authorization": "Bearer 0OWgIous2pQjm2Z4aiT2X0HCt3BnuJnp6fVMVv0TpMpEfW8xL53UkzCFJcAlMEaB", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36", "Content-Type": "application/json;charset=UTF-8", "Origin": "http://127.0.0.1:8000", "Sec-Fetch-Site": "same-origin", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Dest": "empty", "Referer": "http://127.0.0.1:8000/static/index.html", "Accept-Encoding": "gzip, deflate, br", }, "json": {"title": "2222", "is_done": False}, } )
开发
-
获取源代码
git clone https://github.com/dongfangtianyu/har2tavern.git cd har2tavern
-
创建venv,并安装依赖
python -m venv venv source ~/venv/bin/activate pip install -r requirements.txt pre-commit install
-
执行测试、 执行检查
pytest && pre-commit run --all-files
在写代码之前,要确定你获取的代码是没有问题的,所有先执行一次测试
-
开发代码
coding....现在,你可以尽情的编码了。
-
执行测试 、 执行检查
特别提醒你在提交代码之前,再次进行测试和检查
pytest && pre-commit run --all-files
-
打包
python setup.py sdist执行该命令将在
./dist目录下中生成安装包,可以分发、安装
贡献
如果你对本工具有更好的想法,欢迎发起PR https://github.com/dongfangtianyu/har2tavern
我们希望PR中有修改的描述、测试用例,并且所有用例全部测试通过。
Metadata
Release files for har2tavern 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| har2tavern-0.0.2.tar.gz | 5.4 kB | Without provenance | Details for har2tavern-0.0.2.tar.gz |
Release files / har2tavern-0.0.2.tar.gz
| Download URL | har2tavern-0.0.2.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f3a572f394a0c43702e2d39748f16be1c5d9ec46f1eaa1845673cc0e22e44c7
|
|
BLAKE2b-256 checksum How to use checksums |
8fa155f8de8b5cd2e3db355aff6c0d180be49aee5aa46b9677ed11d06f7128cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
|
Security for har2tavern 0.0.2
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.