mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix #361: parameters data error
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# encoding: utf-8
|
||||
|
||||
import copy
|
||||
import os
|
||||
import unittest
|
||||
|
||||
@@ -120,11 +121,8 @@ class HttpRunner(object):
|
||||
|
||||
parsed_testcases_list = []
|
||||
for testcase in testcases:
|
||||
|
||||
config = testcase.setdefault("config", {})
|
||||
|
||||
# parse config parameters
|
||||
config_parameters = config.pop("parameters", [])
|
||||
config_parameters = testcase.setdefault("config", {}).pop("parameters", [])
|
||||
cartesian_product_parameters_list = parser.parse_parameters(
|
||||
config_parameters,
|
||||
self.project_mapping["debugtalk"]["variables"],
|
||||
@@ -132,6 +130,9 @@ class HttpRunner(object):
|
||||
) or [{}]
|
||||
|
||||
for parameter_mapping in cartesian_product_parameters_list:
|
||||
testcase_dict = copy.deepcopy(testcase)
|
||||
config = testcase_dict.setdefault("config", {})
|
||||
|
||||
# parse config variables
|
||||
raw_config_variables = config.get("variables", [])
|
||||
parsed_config_variables = parser.parse_data(
|
||||
@@ -150,25 +151,25 @@ class HttpRunner(object):
|
||||
config_variables = utils.override_mapping_list(
|
||||
config_variables, variables_mapping)
|
||||
|
||||
testcase["config"]["variables"] = config_variables
|
||||
testcase_dict["config"]["variables"] = config_variables
|
||||
|
||||
# parse config name
|
||||
testcase["config"]["name"] = parser.parse_data(
|
||||
testcase["config"].get("name", ""),
|
||||
testcase_dict["config"]["name"] = parser.parse_data(
|
||||
testcase_dict["config"].get("name", ""),
|
||||
config_variables,
|
||||
self.project_mapping["debugtalk"]["functions"]
|
||||
)
|
||||
|
||||
# parse config request
|
||||
testcase["config"]["request"] = parser.parse_data(
|
||||
testcase["config"].get("request", {}),
|
||||
testcase_dict["config"]["request"] = parser.parse_data(
|
||||
testcase_dict["config"].get("request", {}),
|
||||
config_variables,
|
||||
self.project_mapping["debugtalk"]["functions"]
|
||||
)
|
||||
|
||||
# put loaded project functions to config
|
||||
testcase["config"]["functions"] = self.project_mapping["debugtalk"]["functions"]
|
||||
parsed_testcases_list.append(testcase)
|
||||
testcase_dict["config"]["functions"] = self.project_mapping["debugtalk"]["functions"]
|
||||
parsed_testcases_list.append(testcase_dict)
|
||||
|
||||
return parsed_testcases_list
|
||||
|
||||
|
||||
@@ -268,6 +268,8 @@ def load_python_module(module):
|
||||
if validator.is_function((name, item)):
|
||||
debugtalk_module["functions"][name] = item
|
||||
elif validator.is_variable((name, item)):
|
||||
if isinstance(item, tuple):
|
||||
continue
|
||||
debugtalk_module["variables"][name] = item
|
||||
else:
|
||||
pass
|
||||
|
||||
@@ -321,13 +321,21 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
self.assertIn("token", summary["details"][0]["in_out"]["out"])
|
||||
self.assertGreater(len(summary["details"][0]["in_out"]["in"]), 7)
|
||||
|
||||
def test_run_testset_with_parameters(self):
|
||||
def test_run_testcase_with_parameters(self):
|
||||
testcase_file_path = os.path.join(
|
||||
os.getcwd(), 'tests/data/demo_parameters.yml')
|
||||
runner = HttpRunner().run(testcase_file_path)
|
||||
summary = runner.summary
|
||||
self.assertEqual(
|
||||
summary["details"][0]["in_out"]["in"]["user_agent"],
|
||||
"iOS/10.1"
|
||||
)
|
||||
self.assertEqual(
|
||||
summary["details"][2]["in_out"]["in"]["user_agent"],
|
||||
"iOS/10.2"
|
||||
)
|
||||
self.assertEqual(
|
||||
summary["details"][4]["in_out"]["in"]["user_agent"],
|
||||
"iOS/10.3"
|
||||
)
|
||||
self.assertTrue(summary["success"])
|
||||
@@ -362,6 +370,10 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
self.assertEqual(len(parsed_testcases), 2 * 2)
|
||||
self.assertEqual(
|
||||
parsed_testcases[0]["config"]["request"]["base_url"],
|
||||
'$BASE_URL'
|
||||
)
|
||||
self.assertEqual(
|
||||
parsed_testcases[0]["config"]["variables"]["BASE_URL"],
|
||||
'http://127.0.0.1:5000'
|
||||
)
|
||||
self.assertIsInstance(parsed_testcases, list)
|
||||
|
||||
Reference in New Issue
Block a user