From fa7464fca8a54c8868e338d9ae0841701a2a924b Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 19 Jun 2020 23:27:17 +0800 Subject: [PATCH] change: make FROM path in testcase notes relative to project_meta.RootDir --- examples/httpbin/basic_test.py | 4 ++-- examples/httpbin/hooks_test.py | 4 ++-- examples/httpbin/load_image_test.py | 4 ++-- examples/httpbin/upload_test.py | 4 ++-- examples/httpbin/validate_test.py | 4 ++-- .../request_with_functions_test.py | 2 +- .../request_with_testcase_reference_test.py | 2 +- .../request_methods/hardcode_test.py | 2 +- .../request_with_functions_test.py | 2 +- .../request_with_testcase_reference_test.py | 2 +- .../request_with_variables_test.py | 2 +- .../validate_with_functions_test.py | 2 +- .../validate_with_variables_test.py | 2 +- httprunner/make.py | 24 +++++++++++++++++-- 14 files changed, 40 insertions(+), 20 deletions(-) diff --git a/examples/httpbin/basic_test.py b/examples/httpbin/basic_test.py index 9b0241ba..3f912332 100644 --- a/examples/httpbin/basic_test.py +++ b/examples/httpbin/basic_test.py @@ -1,5 +1,5 @@ -# NOTE: Generated By HttpRunner v3.0.13 -# FROM: examples/httpbin/basic.yml +# NOTE: Generated By HttpRunner v3.1.0 +# FROM: basic.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/hooks_test.py b/examples/httpbin/hooks_test.py index 2ab42e00..b9d12e1a 100644 --- a/examples/httpbin/hooks_test.py +++ b/examples/httpbin/hooks_test.py @@ -1,5 +1,5 @@ -# NOTE: Generated By HttpRunner v3.0.13 -# FROM: examples/httpbin/hooks.yml +# NOTE: Generated By HttpRunner v3.1.0 +# FROM: hooks.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/load_image_test.py b/examples/httpbin/load_image_test.py index 50ad9b26..ecbd0aa5 100644 --- a/examples/httpbin/load_image_test.py +++ b/examples/httpbin/load_image_test.py @@ -1,5 +1,5 @@ -# NOTE: Generated By HttpRunner v3.0.13 -# FROM: examples/httpbin/load_image.yml +# NOTE: Generated By HttpRunner v3.1.0 +# FROM: load_image.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/upload_test.py b/examples/httpbin/upload_test.py index c9c04640..826aae8f 100644 --- a/examples/httpbin/upload_test.py +++ b/examples/httpbin/upload_test.py @@ -1,5 +1,5 @@ -# NOTE: Generated By HttpRunner v3.0.13 -# FROM: examples/httpbin/upload.yml +# NOTE: Generated By HttpRunner v3.1.0 +# FROM: upload.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/validate_test.py b/examples/httpbin/validate_test.py index dd1ff6f3..bbbc58e8 100644 --- a/examples/httpbin/validate_test.py +++ b/examples/httpbin/validate_test.py @@ -1,5 +1,5 @@ -# NOTE: Generated By HttpRunner v3.0.13 -# FROM: examples/httpbin/validate.yml +# NOTE: Generated By HttpRunner v3.1.0 +# FROM: validate.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py index 99552365..912fddad 100644 --- a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py +++ b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/request_with_functions.yml +# FROM: request_methods/request_with_functions.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py index 1cbf8a3e..ee4ddeb7 100644 --- a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py +++ b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml +# FROM: request_methods/request_with_testcase_reference.yml import os import sys diff --git a/examples/postman_echo/request_methods/hardcode_test.py b/examples/postman_echo/request_methods/hardcode_test.py index 37d8f295..95e1e421 100644 --- a/examples/postman_echo/request_methods/hardcode_test.py +++ b/examples/postman_echo/request_methods/hardcode_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/hardcode.yml +# FROM: request_methods/hardcode.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase 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 bf25e103..68add82e 100644 --- a/examples/postman_echo/request_methods/request_with_functions_test.py +++ b/examples/postman_echo/request_methods/request_with_functions_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/request_with_functions.yml +# FROM: request_methods/request_with_functions.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/request_with_testcase_reference_test.py b/examples/postman_echo/request_methods/request_with_testcase_reference_test.py index fb0bba19..5fe21f9a 100644 --- a/examples/postman_echo/request_methods/request_with_testcase_reference_test.py +++ b/examples/postman_echo/request_methods/request_with_testcase_reference_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml +# FROM: request_methods/request_with_testcase_reference.yml import os import sys diff --git a/examples/postman_echo/request_methods/request_with_variables_test.py b/examples/postman_echo/request_methods/request_with_variables_test.py index cb287b12..74f38b37 100644 --- a/examples/postman_echo/request_methods/request_with_variables_test.py +++ b/examples/postman_echo/request_methods/request_with_variables_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/request_with_variables.yml +# FROM: request_methods/request_with_variables.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/validate_with_functions_test.py b/examples/postman_echo/request_methods/validate_with_functions_test.py index 56c5f000..68179d7b 100644 --- a/examples/postman_echo/request_methods/validate_with_functions_test.py +++ b/examples/postman_echo/request_methods/validate_with_functions_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/validate_with_functions.yml +# FROM: request_methods/validate_with_functions.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/validate_with_variables_test.py b/examples/postman_echo/request_methods/validate_with_variables_test.py index 6ed3d459..83225fa5 100644 --- a/examples/postman_echo/request_methods/validate_with_variables_test.py +++ b/examples/postman_echo/request_methods/validate_with_variables_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v3.1.0 -# FROM: examples/postman_echo/request_methods/validate_with_variables.yml +# FROM: request_methods/validate_with_variables.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/httprunner/make.py b/httprunner/make.py index 4173254d..856afa49 100644 --- a/httprunner/make.py +++ b/httprunner/make.py @@ -101,6 +101,26 @@ def __ensure_cwd_relative(path: Text) -> Text: return path +def __convert_relative_project_root_dir(abs_path: Text) -> Text: + """ convert absolute path to relative path, based on project_meta.RootDir + + Args: + abs_path: absolute path + + Returns: relative path based on project_meta.RootDir + + """ + project_meta = load_project_meta(abs_path) + if not abs_path.startswith(project_meta.RootDir): + raise exceptions.ParamsError( + f"failed to convert absolute path to relative path based on project_meta.RootDir\n" + f"abs_path: {abs_path}\n" + f"project_meta.RootDir: {project_meta.RootDir}" + ) + + return abs_path[len(project_meta.RootDir) + 1 :] + + def __ensure_testcase_module(path: Text) -> NoReturn: """ ensure pytest files are in python module, generate __init__.py on demand """ @@ -331,7 +351,7 @@ def make_testcase(testcase: Dict, dir_path: Text = None) -> Text: return testcase_python_path config = testcase["config"] - config["path"] = __ensure_cwd_relative(testcase_python_path) + config["path"] = __convert_relative_project_root_dir(testcase_python_path) config["variables"] = convert_variables( config.get("variables", {}), testcase_abs_path ) @@ -370,7 +390,7 @@ def make_testcase(testcase: Dict, dir_path: Text = None) -> Text: data = { "version": __version__, - "testcase_path": __ensure_cwd_relative(testcase_abs_path), + "testcase_path": __convert_relative_project_root_dir(testcase_abs_path), "class_name": f"TestCase{testcase_cls_name}", "imports_list": imports_list, "config_chain_style": make_config_chain_style(config),