fix: ensure variables

This commit is contained in:
debugtalk
2020-06-07 14:50:07 +08:00
parent d1f9b10274
commit ddf5c331cc
5 changed files with 78 additions and 25 deletions

View File

@@ -9,7 +9,11 @@ from loguru import logger
from sentry_sdk import capture_exception
from httprunner import exceptions, __version__
from httprunner.compat import ensure_testcase_v3_api, ensure_testcase_v3
from httprunner.compat import (
ensure_testcase_v3_api,
ensure_testcase_v3,
convert_variables,
)
from httprunner.loader import (
load_folder_files,
load_test_file,
@@ -285,15 +289,9 @@ def make_testcase(testcase: Dict, dir_path: Text = None) -> Text:
config = testcase["config"]
config["path"] = __ensure_cwd_relative(testcase_python_path)
# parse config variables
config.setdefault("variables", {})
if isinstance(config["variables"], Text):
# get variables by function, e.g. ${get_variables()}
project_meta = load_project_meta(testcase_abs_path)
config["variables"] = parse_data(
config["variables"], {}, project_meta.functions
)
config["variables"] = convert_variables(
config.get("variables", {}), testcase_abs_path
)
# prepare reference testcase
imports_list = []
@@ -357,14 +355,9 @@ def make_testsuite(testsuite: Dict) -> NoReturn:
testsuite_config = testsuite["config"]
testsuite_path = testsuite_config["path"]
testsuite_variables = testsuite_config.get("variables", {})
if isinstance(testsuite_variables, Text):
# get variables by function, e.g. ${get_variables()}
project_meta = load_project_meta(testsuite_path)
testsuite_variables = parse_data(
testsuite_variables, {}, project_meta.functions
)
testsuite_variables = convert_variables(
testsuite_config.get("variables", {}), testsuite_path
)
logger.info(f"start to make testsuite: {testsuite_path}")
@@ -392,9 +385,11 @@ def make_testsuite(testsuite: Dict) -> NoReturn:
if "verify" in testsuite_config:
testcase_dict["config"]["verify"] = testsuite_config["verify"]
# override variables
testcase_dict["config"].setdefault("variables", {})
testcase_dict["config"]["variables"].update(testcase.get("variables", {}))
testcase_dict["config"]["variables"].update(testsuite_variables)
testcase_variables = convert_variables(
testcase.get("variables", {}), testcase_path
)
testcase_variables.update(testsuite_variables)
testcase_dict["config"]["variables"] = testcase_variables
# make testcase
testcase_pytest_path = make_testcase(testcase_dict, testsuite_dir)