mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 19:47:14 +08:00
fix: prepare_lazy_data missing output/extract variables when nested testcase as teststep
This commit is contained in:
+16
-7
@@ -841,9 +841,11 @@ def __prepare_testcase_tests(tests, config, project_mapping):
|
|||||||
functions = project_mapping.get("functions", {})
|
functions = project_mapping.get("functions", {})
|
||||||
|
|
||||||
prepared_testcase_tests = []
|
prepared_testcase_tests = []
|
||||||
session_variables = {}
|
session_variables_set = set()
|
||||||
for test_dict in tests:
|
for test_dict in tests:
|
||||||
|
|
||||||
|
teststep_variables_set = {"request", "response"}
|
||||||
|
|
||||||
# 1, testcase config => testcase tests
|
# 1, testcase config => testcase tests
|
||||||
# override test_dict variables
|
# override test_dict variables
|
||||||
test_dict_variables = utils.extend_variables(
|
test_dict_variables = utils.extend_variables(
|
||||||
@@ -867,6 +869,9 @@ def __prepare_testcase_tests(tests, config, project_mapping):
|
|||||||
if "testcase_def" in test_dict:
|
if "testcase_def" in test_dict:
|
||||||
# test_dict is nested testcase
|
# test_dict is nested testcase
|
||||||
|
|
||||||
|
if "output" in test_dict:
|
||||||
|
session_variables_set |= set(test_dict["output"])
|
||||||
|
|
||||||
# 2, testcase test_dict => testcase_def config
|
# 2, testcase test_dict => testcase_def config
|
||||||
testcase_def = test_dict.pop("testcase_def")
|
testcase_def = test_dict.pop("testcase_def")
|
||||||
_extend_with_testcase(test_dict, testcase_def)
|
_extend_with_testcase(test_dict, testcase_def)
|
||||||
@@ -877,12 +882,18 @@ def __prepare_testcase_tests(tests, config, project_mapping):
|
|||||||
# 3, testcase_def config => testcase_def test_dict
|
# 3, testcase_def config => testcase_def test_dict
|
||||||
test_dict = _parse_testcase(test_dict, project_mapping)
|
test_dict = _parse_testcase(test_dict, project_mapping)
|
||||||
|
|
||||||
|
config = test_dict.get("config", {})
|
||||||
|
teststep_variables_set |= set(config.get("variables", []))
|
||||||
|
|
||||||
elif "api_def" in test_dict:
|
elif "api_def" in test_dict:
|
||||||
# test_dict has API reference
|
# test_dict has API reference
|
||||||
# 2, test_dict => api
|
# 2, test_dict => api
|
||||||
api_def_dict = test_dict.pop("api_def")
|
api_def_dict = test_dict.pop("api_def")
|
||||||
_extend_with_api(test_dict, api_def_dict)
|
_extend_with_api(test_dict, api_def_dict)
|
||||||
|
|
||||||
|
# current teststep variables
|
||||||
|
teststep_variables_set |= set(test_dict.get("variables", {}).keys())
|
||||||
|
|
||||||
# verify priority: testcase teststep > testcase config
|
# verify priority: testcase teststep > testcase config
|
||||||
if "request" in test_dict and "verify" not in test_dict["request"]:
|
if "request" in test_dict and "verify" not in test_dict["request"]:
|
||||||
test_dict["request"]["verify"] = config_verify
|
test_dict["request"]["verify"] = config_verify
|
||||||
@@ -890,11 +901,9 @@ def __prepare_testcase_tests(tests, config, project_mapping):
|
|||||||
# move extracted variable to session variables
|
# move extracted variable to session variables
|
||||||
if "extract" in test_dict:
|
if "extract" in test_dict:
|
||||||
extract_mapping = utils.ensure_mapping_format(test_dict["extract"])
|
extract_mapping = utils.ensure_mapping_format(test_dict["extract"])
|
||||||
session_variables.update(extract_mapping)
|
session_variables_set |= set(extract_mapping.keys())
|
||||||
|
|
||||||
check_variables_set = set(test_dict.get("variables", {}).keys()) \
|
teststep_variables_set |= session_variables_set
|
||||||
| set(session_variables.keys()) | {"request", "response"} \
|
|
||||||
| set(test_dict.get("output", []))
|
|
||||||
|
|
||||||
# convert validators to lazy function
|
# convert validators to lazy function
|
||||||
validators = test_dict.pop("validate", [])
|
validators = test_dict.pop("validate", [])
|
||||||
@@ -912,7 +921,7 @@ def __prepare_testcase_tests(tests, config, project_mapping):
|
|||||||
LazyFunction(
|
LazyFunction(
|
||||||
function_meta,
|
function_meta,
|
||||||
functions,
|
functions,
|
||||||
check_variables_set
|
teststep_variables_set
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
test_dict["validate"] = prepared_validators
|
test_dict["validate"] = prepared_validators
|
||||||
@@ -922,7 +931,7 @@ def __prepare_testcase_tests(tests, config, project_mapping):
|
|||||||
prepared_test_dict = prepare_lazy_data(
|
prepared_test_dict = prepare_lazy_data(
|
||||||
test_dict,
|
test_dict,
|
||||||
functions,
|
functions,
|
||||||
check_variables_set
|
teststep_variables_set
|
||||||
)
|
)
|
||||||
prepared_testcase_tests.append(prepared_test_dict)
|
prepared_testcase_tests.append(prepared_test_dict)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user