From 7d286ebc036f307538efb1b740fcc4532ce3fd75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B4=AB=E6=99=B4?= Date: Tue, 8 Jun 2021 13:19:35 +0800 Subject: [PATCH] Add input parameters for clearing log files (#5659) * [skip ci] Update code of test_info Signed-off-by: wangting0128 * [skip ci] Add input parameters for clearing log files Signed-off-by: wangting0128 --- tests20/python_client/base/client_base.py | 14 +++++-- tests20/python_client/common/common_func.py | 3 +- tests20/python_client/config/test_info.py | 8 ++-- tests20/python_client/conftest.py | 6 +-- .../testcases/test_connection.py | 38 +++++++++---------- tests20/python_client/utils/api_request.py | 4 +- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/tests20/python_client/base/client_base.py b/tests20/python_client/base/client_base.py index 6fc335302..68246e438 100644 --- a/tests20/python_client/base/client_base.py +++ b/tests20/python_client/base/client_base.py @@ -12,6 +12,7 @@ from config.test_info import test_info from utils.util_log import test_log as log from common import common_func as cf from common import common_type as ct +from check.param_check import ip_check, number_check class ParamInfo: @@ -72,12 +73,19 @@ class Base: @pytest.fixture(scope="module", autouse=True) def initialize_env(self, request): """ clean log before testing """ - cf.modify_file([test_info.log_debug, test_info.log_info, test_info.log_err]) - log.info("[initialize_milvus] Log cleaned up, start testing...") - host = request.config.getoption("--host") port = request.config.getoption("--port") handler = request.config.getoption("--handler") + clean_log = request.config.getoption("--clean_log") + + """ params check """ + assert ip_check(host) and number_check(port) + + """ modify log files """ + cf.modify_file(file_path_list=[test_info.log_debug, test_info.log_info, test_info.log_err], is_modify=clean_log) + + log.info("#" * 80) + log.info("[initialize_milvus] Log cleaned up, start testing...") param_info.prepare_param_info(host, port, handler) diff --git a/tests20/python_client/common/common_func.py b/tests20/python_client/common/common_func.py index 228704f96..0d8aa962a 100644 --- a/tests20/python_client/common/common_func.py +++ b/tests20/python_client/common/common_func.py @@ -186,6 +186,7 @@ def gen_invalid_dataframe(): ] return dfs + def jaccard(x, y): x = np.asarray(x, np.bool) y = np.asarray(y, np.bool) @@ -241,4 +242,4 @@ def modify_file(file_path_list, is_modify=False, input_content=""): f.truncate() f.write(input_content) f.close() - log.info("[modify_file] File(%s) modification is complete." % file_path_list) + log.info("[modify_file] file(%s) modification is complete." % file_path_list) diff --git a/tests20/python_client/config/test_info.py b/tests20/python_client/config/test_info.py index 19264ebc6..86d203233 100644 --- a/tests20/python_client/config/test_info.py +++ b/tests20/python_client/config/test_info.py @@ -7,20 +7,20 @@ class TestInfo: @staticmethod def get_env_variable(var="CI_LOG_PATH"): - """ get log path of testing """ + """ get log path for testing """ try: log_path = os.environ[var] return str(log_path) except Exception as e: log_path = "/tmp/ci_logs/" - print("Failed to get environment variables : %s, Use default path : %s" % (str(e), log_path)) + print("[get_env_variable] failed to get environment variables : %s, use default path : %s" % (str(e), log_path)) return log_path @staticmethod def create_path(log_path): if not os.path.isdir(str(log_path)): - print("[modify_file] folder(%s) is not exist." % log_path) - print("[modify_file] create path now...") + print("[create_path] folder(%s) is not exist." % log_path) + print("[create_path] create path now...") os.makedirs(log_path) def get_default_config(self): diff --git a/tests20/python_client/conftest.py b/tests20/python_client/conftest.py index 47497017d..a434d6c73 100644 --- a/tests20/python_client/conftest.py +++ b/tests20/python_client/conftest.py @@ -16,7 +16,7 @@ def pytest_addoption(parser): parser.addoption('--search_vectors', action='store', default="search_vectors", help="vectors of search") parser.addoption('--index_param', action='store', default="index_param", help="index_param of index") parser.addoption('--data', action='store', default="data", help="data of request") - parser.addoption('--log_path', action='store', default="/tmp/ci_logs/", help="log path of ci test") + parser.addoption('--clean_log', action='store_true', default=False, help="clean log before testing") @pytest.fixture @@ -90,5 +90,5 @@ def data(request): @pytest.fixture -def log_path(request): - return request.config.getoption("--log_path") +def clean_log(request): + return request.config.getoption("--clean_log") diff --git a/tests20/python_client/testcases/test_connection.py b/tests20/python_client/testcases/test_connection.py index 67ab624a7..81657d212 100644 --- a/tests20/python_client/testcases/test_connection.py +++ b/tests20/python_client/testcases/test_connection.py @@ -14,7 +14,7 @@ class TestConnectionParams(TestcaseBase): """ @pytest.mark.skip("No check for **kwargs") - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_kwargs_param_check(self): """ target: test **kwargs of connection @@ -35,7 +35,7 @@ class TestConnectionParams(TestcaseBase): assert res[0].args[0] == "Fail connecting to server on localhost:19530. Timeout" @pytest.mark.skip("No check for alias") - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) @pytest.mark.parametrize("alias", get_invalid_strs) def test_connection_create_alias_param_check(self, alias): """ @@ -49,7 +49,7 @@ class TestConnectionParams(TestcaseBase): @pytest.mark.skip("No check for alias") @pytest.mark.parametrize("alias", get_invalid_strs) - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_get_alias_param_check(self, alias): """ target: test get connection with wrong params of alias @@ -62,7 +62,7 @@ class TestConnectionParams(TestcaseBase): @pytest.mark.skip("No check for alias") @pytest.mark.parametrize("alias", get_invalid_strs) - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_get_addr_alias_param_check(self, alias): """ target: test get connection addr with wrong params of alias @@ -75,7 +75,7 @@ class TestConnectionParams(TestcaseBase): @pytest.mark.skip("No check for alias") @pytest.mark.parametrize("alias", get_invalid_strs) - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_remove_alias_param_check(self, alias): """ target: test remove connection with wrong params of alias @@ -94,7 +94,7 @@ class TestConnectionOperation(TestcaseBase): The author : Ting.Wang """ - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_configure_repeat(self, host, port): """ target: test connection configure four times @@ -114,7 +114,7 @@ class TestConnectionOperation(TestcaseBase): self.connection_wrap.add_connection() assert self.connection_wrap.list_connections()[0] == [('default', None), ('dev', None), ('default1', None)] - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_remove_connection_not_exist(self): """ target: test remove connection that is not exist @@ -131,7 +131,7 @@ class TestConnectionOperation(TestcaseBase): res = self.connection_wrap.remove_connection(alias=Not_Exist, check_res="") assert res[0].args[0] == "There is no connection with alias '%s'." % Not_Exist - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_remove_connection_repeat(self): """ target: test remove connection twice @@ -145,7 +145,7 @@ class TestConnectionOperation(TestcaseBase): res = self.connection_wrap.remove_connection(alias='default', check_res='') assert res[0].args[0] == "There is no connection with alias 'default'." - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_normal_remove_connection_repeat(self, host, port): """ target: test remove connection twice @@ -163,7 +163,7 @@ class TestConnectionOperation(TestcaseBase): self.connection_wrap.remove_connection(alias='default') self.connection_wrap.remove_connection(alias='dev') - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_remove_connection_100_repeat(self): """ target: test delete the same connection 100 times @@ -177,7 +177,7 @@ class TestConnectionOperation(TestcaseBase): res = self.connection_wrap.remove_connection(alias='default', check_res='') assert res[0].args[0] == "There is no connection with alias 'default'." - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_configure_remove_connection(self, host, port): """ target: test remove configure alias @@ -191,7 +191,7 @@ class TestConnectionOperation(TestcaseBase): assert res[0].args[0] == "There is no connection with alias '%s'." % alias_name @pytest.mark.skip("error res") - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_create_connection_remove_configure(self, host, port): """ target: test create connection before remove configure @@ -204,7 +204,7 @@ class TestConnectionOperation(TestcaseBase): self.connection_wrap.get_connection(alias=alias_name) @pytest.mark.skip("error res") - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_create_connection_reset_configure(self, host, port): """ target: test params of create connection are different with configure @@ -217,7 +217,7 @@ class TestConnectionOperation(TestcaseBase): self.connection_wrap.get_connection(alias=alias_name) @pytest.mark.skip("res needs to be confirmed") - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_create_connection_diff_configure(self, host, port): """ target: test params of create connection are different with configure @@ -231,7 +231,7 @@ class TestConnectionOperation(TestcaseBase): res = self.connection_wrap.connect(alias="default", host=host, port=port, check_task='') log.info(res[0]) - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_create_connection_repeat(self, host, port): """ target: test create connection twice @@ -244,7 +244,7 @@ class TestConnectionOperation(TestcaseBase): self.connection_wrap.connect(alias='default', host=host, port=port) self.connection_wrap.get_connection(alias='default') - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_create_connection_not_exist(self, port): """ target: test create connection is not exist @@ -255,7 +255,7 @@ class TestConnectionOperation(TestcaseBase): res = self.connection_wrap.connect(alias="default", host='host', port=port, check_task='') assert res[0].args[0] == "Fail connecting to server on host:19530. Timeout" - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_create_remove(self, host, port): """ target: test create and remove connection twice @@ -270,7 +270,7 @@ class TestConnectionOperation(TestcaseBase): self.connection_wrap.connect(alias=alias_name, host=host, port=port) self.connection_wrap.get_connection(alias=alias_name) - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_list_configure(self, host, port): """ target: test list connection of configure @@ -282,7 +282,7 @@ class TestConnectionOperation(TestcaseBase): assert self.connection_wrap.list_connections()[0] == ['default', 'dev'] @pytest.mark.skip("Behavior to be determined") - @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.tags(CaseLabel.L3) def test_connection_list_create_configure(self, host, port): """ target: test list connection of configure diff --git a/tests20/python_client/utils/api_request.py b/tests20/python_client/utils/api_request.py index ff5e9cf69..3b0703d40 100644 --- a/tests20/python_client/utils/api_request.py +++ b/tests20/python_client/utils/api_request.py @@ -12,7 +12,7 @@ def api_request_catch(): def inner_wrapper(*args, **kwargs): try: res = func(*args, **kwargs) - log.debug("(func_res) Response : %s " % str(res)) + log.debug("(api_res) Response : %s " % str(res)) return res, True except Exception as e: log.error("[Milvus API Exception]%s: %s" % (str(func), str(e))) @@ -30,6 +30,6 @@ def api_request(_list, **kwargs): if len(_list) > 1: for a in _list[1:]: arg.append(a) - log.debug("(func_req)[%s] Parameters ars arg: %s, kwargs: %s" % (str(func), str(arg), str(kwargs))) + log.debug("(api_req)[%s] Parameters ars arg: %s, kwargs: %s" % (str(func), str(arg), str(kwargs))) return func(*arg, **kwargs) return False, False -- GitLab