change: make FROM path in testcase notes relative to project_meta.RootDir

This commit is contained in:
debugtalk
2020-06-19 23:27:17 +08:00
parent 1918f62c64
commit c92ea39e7c
14 changed files with 40 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.0.13 # NOTE: Generated By HttpRunner v3.1.0
# FROM: examples/httpbin/basic.yml # FROM: basic.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.0.13 # NOTE: Generated By HttpRunner v3.1.0
# FROM: examples/httpbin/hooks.yml # FROM: hooks.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.0.13 # NOTE: Generated By HttpRunner v3.1.0
# FROM: examples/httpbin/load_image.yml # FROM: load_image.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.0.13 # NOTE: Generated By HttpRunner v3.1.0
# FROM: examples/httpbin/upload.yml # FROM: upload.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.0.13 # NOTE: Generated By HttpRunner v3.1.0
# FROM: examples/httpbin/validate.yml # FROM: validate.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 os
import sys import sys

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 os
import sys import sys

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.0 # 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 from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -101,6 +101,26 @@ def __ensure_cwd_relative(path: Text) -> Text:
return path 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: def __ensure_testcase_module(path: Text) -> NoReturn:
""" ensure pytest files are in python module, generate __init__.py on demand """ 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 return testcase_python_path
config = testcase["config"] 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["variables"] = convert_variables(
config.get("variables", {}), testcase_abs_path config.get("variables", {}), testcase_abs_path
) )
@@ -370,7 +390,7 @@ def make_testcase(testcase: Dict, dir_path: Text = None) -> Text:
data = { data = {
"version": __version__, "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}", "class_name": f"TestCase{testcase_cls_name}",
"imports_list": imports_list, "imports_list": imports_list,
"config_chain_style": make_config_chain_style(config), "config_chain_style": make_config_chain_style(config),