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 断言方法
comparator缩写功能equal“eq”, “equals”, “equal”相等less_than“lt”, “less_than”小于less_or_equals“le”, “less_or_equals”小于或等于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”长度小于或等于containscheck_value 包含 expect_valuecontained_byexpect_value 包含check_valuetype_matchtype类型匹配regex_match正则匹配re.match(expect_value, check_value)startswith字符串以xx开头endswith字符串以xx结尾————————————————版权声明:本文为CSDN博主「上海-悠悠」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/qq_27371025/article/details/118208941 标签:断言,less,httprunner3,equals,assert,length,validate,than,greater From: https://www.cnblogs.com/listening-y/p/17191602.html