zoukankan      html  css  js  c++  java
  • pytest学习系列_pytest-timeout插件之设置超时时间

    一、前言

      在我们做接口自动化的时候,很经常会有一个指标是找出一些耗时的接口,从而告知开发这些接口需要优化

    二、安装

      pip install pytest-timeout

    三、使用方法

      1、代码示例

    #!/usr/bin/python3
    # -*- coding: UTF-8 -*-
    """
    @author:durant.zeng
    @Description:描述
    @file:test_baidu.py
    @time:2020/12/17
    """
    import time
    import requests
    
    def test_baidu():
        time.sleep(5)
        r = requests.get(url='https://baidu.com')
        print(r.elapsed.total_seconds())

      2、命令行参数执行

    pytest --timeout=2

      3、存放到pytest.ini,直接执行pytest

    [pytest]
    timeout = 2

       pytest

    结论:执行此用例,会失败,比较好的模拟出耗时长而失败的场景

    知道、想到、做到、得到
  • 相关阅读:
    java多线程
    golang编码转换
    golang csv,xls,xlsx
    golang 资源
    electron安装
    Ubuntu系统下面软件安装更新命令
    golang代码执行顺序
    datatables使用
    Echarts柱形图颜色设置
    golang chan 超时
  • 原文地址:https://www.cnblogs.com/Durant0420/p/14148946.html
Copyright © 2011-2022 走看看