【问题标题】:How to set timeout as variable in Tavern test?如何在 Tavern 测试中将超时设置为变量?
【发布时间】:2019-09-04 07:07:45
【问题描述】:

我有两个用于测试的 yaml 文件,common.yamltest.yamlcommon.yaml中定义了一些变量:

name: Common test information
description: Common data used by test cases

variables:
  url: http://localhost:8080/v2
  timeout: 30

在测试文件中:

includes:
  - !include common.yaml

stages:
  - name: test
    request:
      url: "{url:s}/test"
      method: GET
      timeout: "{timeout:d}"
    response:
      status_code: 200

它使用在common 文件中定义的timeout。运行测试时出现此错误:

tavern.util.exceptions.BadSchemaError: 'timeout' must be either a float/int or a 2-tuple of floats/ints - got '{timeout:d}' (type <class 'str'>)

Tavern 似乎无法识别timeout 的类型。最后我已经指定类型是d,但是为什么它不接。

【问题讨论】:

    标签: python pytest tavern


    【解决方案1】:

    使用超时:!int "{timeout:d}"

    或超时:!float "{timeout:f}"

    从字符串转换类型

    【讨论】:

      猜你喜欢
      • 2021-08-22
      • 1970-01-01
      • 2010-11-02
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-18
      相关资源
      最近更新 更多