test: add assert message if assert failed ()

add assert message if assert failed

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
pull/29088/head
zhuwenxing 2024-01-23 16:07:01 +08:00 committed by GitHub
parent 463765922e
commit 24bbb12166
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 11 deletions
tests/python_client/check

View File

@ -91,11 +91,11 @@ class ResponseChecker:
elif self.check_task == CheckTasks.check_permission_deny: elif self.check_task == CheckTasks.check_permission_deny:
# Collection interface response check # Collection interface response check
result = self.check_permission_deny(self.response, self.succ) result = self.check_permission_deny(self.response, self.succ)
elif self.check_task == CheckTasks.check_rg_property: elif self.check_task == CheckTasks.check_rg_property:
# describe resource group interface response check # describe resource group interface response check
result = self.check_rg_property(self.response, self.func_name, self.check_items) result = self.check_rg_property(self.response, self.func_name, self.check_items)
elif self.check_task == CheckTasks.check_describe_collection_property: elif self.check_task == CheckTasks.check_describe_collection_property:
# describe collection interface(high level api) response check # describe collection interface(high level api) response check
result = self.check_describe_collection_property(self.response, self.func_name, self.check_items) result = self.check_describe_collection_property(self.response, self.func_name, self.check_items)
@ -104,21 +104,25 @@ class ResponseChecker:
return result return result
@staticmethod def assert_succ(self, actual, expect):
def assert_succ(actual, expect): assert actual is expect, f"Response of API {self.func_name} expect {expect}, but got {actual}"
assert actual is expect
return True return True
@staticmethod def assert_exception(self, res, actual=True, error_dict=None):
def assert_exception(res, actual=True, error_dict=None):
assert actual is False assert actual is False
assert len(error_dict) > 0 assert len(error_dict) > 0
if isinstance(res, Error): if isinstance(res, Error):
error_code = error_dict[ct.err_code] error_code = error_dict[ct.err_code]
assert res.code == error_code or error_dict[ct.err_msg] in res.message assert res.code == error_code or error_dict[ct.err_msg] in res.message, (
f"Response of API {self.func_name} "
f"expect get error code {error_dict[ct.err_code]} or error message {error_dict[ct.err_code]}, "
f"but got {res.code} {res.message}")
else: else:
log.error("[CheckFunc] Response of API is not an error: %s" % str(res)) log.error("[CheckFunc] Response of API is not an error: %s" % str(res))
assert False assert False, (f"Response of API expect get error code {error_dict[ct.err_code]} or "
f"error message {error_dict[ct.err_code]}"
f"but success")
return True return True
@staticmethod @staticmethod
@ -342,7 +346,7 @@ class ResponseChecker:
check_items["metric"], hits.distances) check_items["metric"], hits.distances)
log.info("search_results_check: Checked the distances for one nq: OK") log.info("search_results_check: Checked the distances for one nq: OK")
else: else:
pass # just check nq and topk, not specific ids need check pass # just check nq and topk, not specific ids need check
log.info("search_results_check: limit (topK) and " log.info("search_results_check: limit (topK) and "
"ids searched for %d queries are correct" % len(search_res)) "ids searched for %d queries are correct" % len(search_res))
@ -415,7 +419,7 @@ class ResponseChecker:
primary_field = check_items.get("primary_field", None) primary_field = check_items.get("primary_field", None)
if exp_res is not None: if exp_res is not None:
if isinstance(query_res, list): if isinstance(query_res, list):
assert pc.equal_entities_list(exp=exp_res, actual=query_res, primary_field=primary_field, assert pc.equal_entities_list(exp=exp_res, actual=query_res, primary_field=primary_field,
with_vec=with_vec) with_vec=with_vec)
return True return True
else: else: