httprunner3.X validate 断言
1、validate 可以支持的校验方式
项目 | 缩写 | 功能 |
equal | “eq”, “equals”, “equal” | 相等 |
less_than | “lt”, “less_than” | 小于 |
less_or_equals | “le”, “less_or_equals” | `2112小于或等于 |
greater_than | “gt”, “greater_than” | 大于 |
greater_or_equals | “ge”, “greater_or_equals” | 大于或等于 |
not_equal | “ne”, “not_equal” | 不等于 |
string_equals | “str_eq”, “string_equals” | 转字符串相等 |
length_equal | “len_eq”, “length_equal” | 长度相等 |
length_greater_than | “len_gt”,“length_greater_than” | 长度大于 |
length_greater_or_equals | “len_ge”,“length_greater_or_equals” | 长度大于或等于 |
length_less_than | “len_lt”, “length_less_than” | 长度小于 |
length_less_or_equals | “len_le”, “length_less_or_equals” | 长度小于或等于 |
contains | check_value | 包含 expect_value |
contained_by | expect_value 包含check_value | |
type_match | type类型匹配 | |
regex_match | 正则匹配re.match(expect_value, check_value) | |
startswith | 字符串以xx开头 | |
endswith | 字符串以xx结尾 |
2、yaml 中可以写2种格式校验
{“comparator_name”: [check_value, expect_value]}
{“check”: check_value, “comparator”: comparator_name, “expect”: expect_value}
3、pytest脚本中的断言
方法 | 对应校验方法 | 功能 |
assert_equal | equal | 相等 |
assert_not_equal | not_equal | 不等于 |
assert_less_than | less_than | 小于 |
assert_less_or_equals | less_or_equals | 小于或等于 |
assert_greater_than | greater_than | 大于 |
assert_greater_or_equals | greater_or_equals | 大于或等于 |
assert_assert_string_equals | string_equals | 转字符串相等 |
assert_length_equal | length_equal | 长度相等 |
assert_length_greater_than | length_greater_than | 长度大于 |
assert_length_greater_or_equals | length_greater_or_equals | 长度大于或等于 |
assert_length_less_than | length_less_than | 长度小于 |
assert_length_less_or_equals | length_less_or_equals | 长度小于或等于 |
assert_contains | contains | check_value 包含 expect_value |
assert_contained_by | contained_by | expect_value 包含check_value |
assert_type_match | type_match | type类型匹配 |
assert_regex_match | regex_match | 正则匹配re.match(expect_value, check_value) |
assert_startswith | startswith | 字符串以xx开头 |
assert_endswith | endswith | 字符串以xx结尾 |
使用方式先调用 .validate()
方法,才能调用 assert 断言方法