From 477bce0816977d5e01b96a893ed6d3fd38e1dfcd Mon Sep 17 00:00:00 2001 From: HarrisChu <1726587+HarrisChu@users.noreply.github.com> Date: Thu, 20 Oct 2022 13:43:50 +0800 Subject: [PATCH] logging error if any error in step --- tests/conftest.py | 48 +++++++++++++++++++++++-------------------- tests/tck/conftest.py | 28 ++++++++++++++----------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3bb15a16f3b..260da26c253 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -50,31 +50,36 @@ def pytest_runtest_logreport(report): def pytest_addoption(parser): for config in all_configs: - parser.addoption(config, - dest=all_configs[config][0], - default=all_configs[config][1], - help=all_configs[config][2]) + parser.addoption( + config, + dest=all_configs[config][0], + default=all_configs[config][1], + help=all_configs[config][2], + ) - parser.addoption("--build_dir", - dest="build_dir", - default=BUILD_DIR, - help="NebulaGraph CMake build directory") - parser.addoption("--src_dir", - dest="src_dir", - default=NEBULA_HOME, - help="NebulaGraph workspace") + parser.addoption( + "--build_dir", + dest="build_dir", + default=BUILD_DIR, + help="NebulaGraph CMake build directory", + ) + parser.addoption( + "--src_dir", dest="src_dir", default=NEBULA_HOME, help="NebulaGraph workspace" + ) def pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func_args): - logging.info("=== more error information ===") - logging.info("feature is {}".format(feature.filename)) - logging.info("step line number is {}".format(step.line_number)) - logging.info("step name is {}".format(step.name)) - if step_func_args.get("graph_spaces") is not None: + logging.error("Location: {}:{}".format(feature.filename, step.line_number)) + logging.error("Step: {}".format(step.name)) + graph_spaces = None + if graph_spaces is None and step_func_args.get("graph_spaces") is not None: graph_spaces = step_func_args.get("graph_spaces") - if graph_spaces.get("space_desc") is not None: - logging.info("error space is {}".format( - graph_spaces.get("space_desc"))) + + if graph_spaces is None and step_func_args.get("exec_ctx") is not None: + graph_spaces = step_func_args.get("exec_ctx") + + if graph_spaces is not None and graph_spaces.get("space_desc") is not None: + logging.error("Space: {}".format(graph_spaces.get("space_desc"))) def pytest_configure(config): @@ -125,8 +130,7 @@ def get_ssl_config_from_tmp(): @pytest.fixture(scope="class") def class_fixture_variables(): - """save class scope fixture, used for session update. - """ + """save class scope fixture, used for session update.""" # cluster is the instance of NebulaService # current_session is the session currently using # sessions is a list of all sessions in the cluster diff --git a/tests/tck/conftest.py b/tests/tck/conftest.py index 140064f7cc0..fd1d828eab8 100644 --- a/tests/tck/conftest.py +++ b/tests/tck/conftest.py @@ -405,21 +405,27 @@ def executing_query(query, exec_ctx, request): ngql = combine_query(query) exec_query(request, ngql, exec_ctx) -@when(parse("executing query and retrying it on failure every {secs:d} seconds for {retryTimes:d} times:\n{query}")) + +@when( + parse( + "executing query and retrying it on failure every {secs:d} seconds for {retryTimes:d} times:\n{query}" + ) +) def executing_query_with_retry(query, exec_ctx, request, secs, retryTimes): ngql = combine_query(query) exec_query(request, ngql, exec_ctx) res = exec_ctx["result_set"] if not res.is_succeeded(): - retryCounter = 0 - while retryCounter < retryTimes: - time.sleep(secs) - exec_query(request, ngql, exec_ctx) - resRetry = exec_ctx["result_set"] - if not resRetry.is_succeeded(): - retryCounter = retryCounter + 1 - else: - break + retryCounter = 0 + while retryCounter < retryTimes: + time.sleep(secs) + exec_query(request, ngql, exec_ctx) + resRetry = exec_ctx["result_set"] + if not resRetry.is_succeeded(): + retryCounter = retryCounter + 1 + else: + break + @when(parse("executing query with user {username} with password {password}:\n{query}")) def executing_query( @@ -572,13 +578,11 @@ def rowp(ds, i): if not res: scen = request.function.__scenario__ feature = scen.feature.rel_filename - location = f"{feature}:{line_number(scen._steps, result)}" msg = [ f"Fail to exec: {ngql}", f"Response: {dsp(rds)}", f"Expected: {dsp(ds)}", f"NotFoundRow: {rowp(ds, i)}", - f"Location: {location}", f"Space: {str(space_desc)}", f"vid_fn: {vid_fn}", ]