mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
update parse_parameters
This commit is contained in:
@@ -20,18 +20,6 @@ class HttpRunner(object):
|
||||
failfast (bool): False/True, stop the test run on the first error or failure.
|
||||
http_client_session (instance): requests.Session(), or locust.client.Session() instance.
|
||||
|
||||
Attributes:
|
||||
project_mapping (dict): save project loaded api/testcases, environments and debugtalk.py module.
|
||||
{
|
||||
"debugtalk": {
|
||||
"variables": {},
|
||||
"functions": {}
|
||||
},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
}
|
||||
|
||||
"""
|
||||
self.exception_stage = "initialize HttpRunner()"
|
||||
self.http_client_session = kwargs.pop("http_client_session", None)
|
||||
@@ -47,7 +35,7 @@ class HttpRunner(object):
|
||||
testcases (list): parsed testcases list
|
||||
|
||||
Returns:
|
||||
tuple: unittest.TestSuite()
|
||||
unittest.TestSuite()
|
||||
|
||||
"""
|
||||
def _add_teststep(test_runner, config, teststep_dict):
|
||||
@@ -165,10 +153,7 @@ class HttpRunner(object):
|
||||
"variables": [], # optional
|
||||
"request": {} # optional
|
||||
"refs": {
|
||||
"debugtalk": {
|
||||
"variables": {},
|
||||
"functions": {}
|
||||
},
|
||||
"functions": {},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
|
||||
@@ -255,7 +255,7 @@ def substitute_variables(content, variables_mapping):
|
||||
|
||||
return content
|
||||
|
||||
def parse_parameters(parameters, variables_mapping, functions_mapping):
|
||||
def parse_parameters(parameters, variables_mapping=None, functions_mapping=None):
|
||||
""" parse parameters and generate cartesian product.
|
||||
|
||||
Args:
|
||||
@@ -265,7 +265,7 @@ def parse_parameters(parameters, variables_mapping, functions_mapping):
|
||||
(2) call built-in parameterize function, "${parameterize(account.csv)}"
|
||||
(3) call custom function in debugtalk.py, "${gen_app_version()}"
|
||||
|
||||
variables_mapping (dict): variables mapping loaded from debugtalk.py
|
||||
variables_mapping (dict): variables mapping loaded from testcase config
|
||||
functions_mapping (dict): functions mapping loaded from debugtalk.py
|
||||
|
||||
Returns:
|
||||
@@ -280,7 +280,10 @@ def parse_parameters(parameters, variables_mapping, functions_mapping):
|
||||
>>> parse_parameters(parameters)
|
||||
|
||||
"""
|
||||
variables_mapping = variables_mapping or {}
|
||||
functions_mapping = functions_mapping or {}
|
||||
parsed_parameters_list = []
|
||||
|
||||
for parameter in parameters:
|
||||
parameter_name, parameter_content = list(parameter.items())[0]
|
||||
parameter_name_list = parameter_name.split("-")
|
||||
@@ -542,7 +545,7 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
"config": {
|
||||
"name": "desc1",
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
"variables": {}, # optional
|
||||
"request": {} # optional
|
||||
"refs": {
|
||||
"debugtalk": {
|
||||
@@ -598,7 +601,7 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
config_parameters = testcase_config.pop("parameters", [])
|
||||
cartesian_product_parameters_list = parse_parameters(
|
||||
config_parameters,
|
||||
{},
|
||||
testcase_config.get("variables", {}),
|
||||
project_mapping["functions"]
|
||||
) or [{}]
|
||||
|
||||
|
||||
@@ -364,8 +364,7 @@ class TestParser(unittest.TestCase):
|
||||
]
|
||||
variables_mapping = {}
|
||||
functions_mapping = {}
|
||||
cartesian_product_parameters = parser.parse_parameters(
|
||||
parameters, variables_mapping, functions_mapping)
|
||||
cartesian_product_parameters = parser.parse_parameters(parameters)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
3 * 2
|
||||
@@ -389,11 +388,9 @@ class TestParser(unittest.TestCase):
|
||||
)
|
||||
loader.load_dot_env_file(dot_env_path)
|
||||
from tests import debugtalk
|
||||
functions = loader.load_module_functions(debugtalk)
|
||||
cartesian_product_parameters = parser.parse_parameters(
|
||||
parameters,
|
||||
{},
|
||||
functions
|
||||
functions_mapping=loader.load_module_functions(debugtalk)
|
||||
)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
@@ -405,11 +402,7 @@ class TestParser(unittest.TestCase):
|
||||
{"app_version": "${parameterize(tests/data/app_version.csv)}"},
|
||||
{"username-password": "${parameterize(tests/data/account.csv)}"}
|
||||
]
|
||||
variables_mapping = {}
|
||||
functions_mapping = {}
|
||||
|
||||
cartesian_product_parameters = parser.parse_parameters(
|
||||
parameters, variables_mapping, functions_mapping)
|
||||
cartesian_product_parameters = parser.parse_parameters(parameters)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
2 * 3
|
||||
@@ -424,13 +417,12 @@ class TestParser(unittest.TestCase):
|
||||
{"username-password": "${parameterize(tests/data/account.csv)}"}
|
||||
]
|
||||
variables_mapping = {}
|
||||
functions_mapping = project_mapping["functions"]
|
||||
testcase_path = os.path.join(
|
||||
os.getcwd(),
|
||||
"tests/data/demo_parameters.yml"
|
||||
)
|
||||
cartesian_product_parameters = parser.parse_parameters(
|
||||
parameters, variables_mapping, functions_mapping)
|
||||
parameters, functions_mapping=project_mapping["functions"])
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
3 * 2 * 3
|
||||
|
||||
Reference in New Issue
Block a user