pytest-requestselapsed
当前插件对 requests 库进行简单的封装使它成为一个 fixture 对象.
安装插件
pip3 install pytest-requestselapsed
测试用例
test_case.py
不需要导入 requests 库, 在测试函数入口声明使用 requests Fixture就具备使用 requests 库的能力.
def test_baidu(requests):
resp = requests.get("https://www.baidu.com")
assert resp.status_code < 400
def test_qq(requests):
resp = requests.get("https://weixin.qq.com/")
assert resp.status_code < 400
def test_taobao(requests):
resp = requests.get("https://www.taobao.com")
assert resp.status_code < 400
def test_bilibili(requests):
resp = requests.get("https://www.bilibili.com")
assert resp.status_code < 400
测试报告
-
默认表现
$ cd example/readme/ $ pytest ======================================= test session starts ======================================= platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0 rootdir: /home/zt/PycharmProjects/pytest-requestselapsed/example/readme plugins: requestselapsed-0.0.1 collected 4 items test_case.py .... [100%] ======================================== 4 passed in 1.44s ========================================
-
在控制台打印api响应报告
$ cd example/readme/ $ pytest --output-mode=console ============================================= test session starts ============================================= platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0 rootdir: /home/zt/PycharmProjects/pytest-requestselapsed/example/readme plugins: requestselapsed-0.0.1 collected 4 items test_case.py .... [100%] elapsed method url 0.690789 GET https://www.bilibili.com/?rt=V%2FymTlOu4ow%2Fy4xxNWPUZxCA8HpNf6nrCC8%2BjIwXT0M%3D 0.572896 GET https://www.bilibili.com/ 0.498390 GET https://www.baidu.com/ 0.387840 GET https://weixin.qq.com/ 0.159209 GET https://www.taobao.com/ ============================================== 4 passed in 1.58s ==============================================
-
在飞书群聊窗口打印api响应报告
$ cd example/readme/ $ pytest --output-mode=feishu --feishu-webhook-url=https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ======================================= test session starts ======================================= platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0 rootdir: /home/zt/PycharmProjects/pytest-requestselapsed/example/readme plugins: requestselapsed-0.0.1 collected 4 items test_case.py .... [100%] ======================================== 4 passed in 1.44s ========================================
更多案例
Metadata
Release files for pytest-requestselapsed 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-requestselapsed-0.0.3.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_requestselapsed-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.0 kB
Release files / pytest-requestselapsed-0.0.3.tar.gz
| Download URL | pytest-requestselapsed-0.0.3.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5885d5b53b073e6bfb09108a718b87a652732ac1f79d17ee1eee0c28bd57bd75
|
|
BLAKE2b-256 checksum How to use checksums |
84843b04f4da3e58c316bcfbe2c0fabfc1aa6aa30d3ccce01ff2cf34ad2d2678
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / pytest_requestselapsed-0.0.3-py3-none-any.whl
| Download URL | pytest_requestselapsed-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
181b39e60f8f8b2733354d9cba939f98d6c8750069f5f98a1f965f3132f6520d
|
|
BLAKE2b-256 checksum How to use checksums |
549390512570eecf44da9194b9b0c6cb29d4b1c69d58f048792066d4da27463f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|