Skip to main content

collect and show http requests elapsed time

Project description

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 ========================================  
    

    feishu_webhook.png

 
更多案例

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

pytest-requestselapsed-0.0.3.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

pytest_requestselapsed-0.0.3-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

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