mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 03:30:01 +08:00
feat: testsuite config get variables by call function
This commit is contained in:
@@ -7,3 +7,9 @@ def get_httprunner_version():
|
|||||||
|
|
||||||
def sum_two(m, n):
|
def sum_two(m, n):
|
||||||
return m + n
|
return m + n
|
||||||
|
|
||||||
|
|
||||||
|
def get_variables():
|
||||||
|
return {
|
||||||
|
"foo1": "session_bar1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
config:
|
config:
|
||||||
name: "demo testsuite"
|
name: "demo testsuite"
|
||||||
# variables: ${get_variable()}
|
variables: ${get_variables()}
|
||||||
|
|
||||||
testcases:
|
testcases:
|
||||||
-
|
-
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ from httprunner.loader import (
|
|||||||
load_test_file,
|
load_test_file,
|
||||||
load_testcase,
|
load_testcase,
|
||||||
load_testsuite,
|
load_testsuite,
|
||||||
get_project_working_directory,
|
load_project_meta,
|
||||||
)
|
)
|
||||||
|
from httprunner.parser import parse_data
|
||||||
|
|
||||||
__TMPL__ = """# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
__TMPL__ = """# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
||||||
# FROM: {{ testcase_path }}
|
# FROM: {{ testcase_path }}
|
||||||
@@ -112,10 +113,19 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
|||||||
|
|
||||||
config = testsuite["config"]
|
config = testsuite["config"]
|
||||||
testsuite_path = config["path"]
|
testsuite_path = config["path"]
|
||||||
|
project_meta = load_project_meta(testsuite_path)
|
||||||
|
project_working_directory = project_meta.PWD
|
||||||
|
|
||||||
|
testsuite_variables = config.get("variables", {})
|
||||||
|
if isinstance(testsuite_variables, Text):
|
||||||
|
# get variables by function, e.g. ${get_variables()}
|
||||||
|
testsuite_variables = parse_data(
|
||||||
|
testsuite_variables, {}, project_meta.functions
|
||||||
|
)
|
||||||
|
|
||||||
logger.info(f"start to make testsuite: {testsuite_path}")
|
logger.info(f"start to make testsuite: {testsuite_path}")
|
||||||
|
|
||||||
testcase_files = []
|
testcase_files = []
|
||||||
project_working_directory = get_project_working_directory(testsuite_path)
|
|
||||||
|
|
||||||
for testcase in testsuite["testcases"]:
|
for testcase in testsuite["testcases"]:
|
||||||
# get referenced testcase content
|
# get referenced testcase content
|
||||||
@@ -132,12 +142,8 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
|||||||
testcase_dict["config"]["base_url"] = base_url
|
testcase_dict["config"]["base_url"] = base_url
|
||||||
# override variables
|
# override variables
|
||||||
testcase_dict["config"].setdefault("variables", {})
|
testcase_dict["config"].setdefault("variables", {})
|
||||||
testcase_dict["config"]["variables"].update(
|
testcase_dict["config"]["variables"].update(testcase.get("variables", {}))
|
||||||
testcase.get("variables", {})
|
testcase_dict["config"]["variables"].update(testsuite_variables)
|
||||||
)
|
|
||||||
testcase_dict["config"]["variables"].update(
|
|
||||||
testsuite["config"].get("variables", {})
|
|
||||||
)
|
|
||||||
|
|
||||||
# create directory with testsuite file name, put its testcases under this directory
|
# create directory with testsuite file name, put its testcases under this directory
|
||||||
testcase_dict["config"]["path"] = os.path.join(
|
testcase_dict["config"]["path"] = os.path.join(
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class TConfig(BaseModel):
|
|||||||
name: Name
|
name: Name
|
||||||
verify: Verify = False
|
verify: Verify = False
|
||||||
base_url: BaseUrl = ""
|
base_url: BaseUrl = ""
|
||||||
variables: VariablesMapping = {}
|
# Text: prepare variables in debugtalk.py, ${get_variable()}
|
||||||
|
variables: Union[VariablesMapping, Text] = {}
|
||||||
setup_hooks: Hook = []
|
setup_hooks: Hook = []
|
||||||
teardown_hooks: Hook = []
|
teardown_hooks: Hook = []
|
||||||
export: Export = []
|
export: Export = []
|
||||||
|
|||||||
Reference in New Issue
Block a user