diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index cabaac4b..1a104309 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 3.1.1 (2020-06-21) + +**Fixed** + +- fix #942: type_match None + ## 3.1.0 (2020-06-21) **Added** diff --git a/examples/postman_echo/request_methods/request_with_functions.yml b/examples/postman_echo/request_methods/request_with_functions.yml index b99bdbc3..634875d8 100644 --- a/examples/postman_echo/request_methods/request_with_functions.yml +++ b/examples/postman_echo/request_methods/request_with_functions.yml @@ -48,6 +48,9 @@ teststeps: validate: - eq: ["status_code", 200] - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar21."] + - type_match: ["body.json", None] + - type_match: ["body.json", NoneType] + - type_match: ["body.json", null] - name: post form data variables: diff --git a/examples/postman_echo/request_methods/request_with_functions_test.py b/examples/postman_echo/request_methods/request_with_functions_test.py index 68add82e..4ed62183 100644 --- a/examples/postman_echo/request_methods/request_with_functions_test.py +++ b/examples/postman_echo/request_methods/request_with_functions_test.py @@ -57,6 +57,9 @@ class TestCaseRequestWithFunctions(HttpRunner): "body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar21.", ) + .assert_type_match("body.json", "None") + .assert_type_match("body.json", "NoneType") + .assert_type_match("body.json", None) ), Step( RunRequest("post form data") diff --git a/httprunner/builtin/comparators.py b/httprunner/builtin/comparators.py index 2a8ab78c..b81919b3 100644 --- a/httprunner/builtin/comparators.py +++ b/httprunner/builtin/comparators.py @@ -80,7 +80,10 @@ def type_match(check_value, expect_value): else: raise ValueError(name) - assert isinstance(check_value, get_type(expect_value)) + if expect_value in ["None", "NoneType", None]: + assert check_value is None + else: + assert type(check_value) == get_type(expect_value) def regex_match(check_value, expect_value): diff --git a/tests/utils_test.py b/tests/utils_test.py index 159ea4e1..99771c25 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -69,6 +69,9 @@ class TestUtils(unittest.TestCase): functions_mapping["type_match"]([1], "list") functions_mapping["type_match"]({}, "dict") functions_mapping["type_match"]({"a": 1}, "dict") + functions_mapping["type_match"](None, "None") + functions_mapping["type_match"](None, "NoneType") + functions_mapping["type_match"](None, None) def test_lower_dict_keys(self): request_dict = {