mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-12 03:09:43 +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.
|
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.
|
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.exception_stage = "initialize HttpRunner()"
|
||||||
self.http_client_session = kwargs.pop("http_client_session", None)
|
self.http_client_session = kwargs.pop("http_client_session", None)
|
||||||
@@ -47,7 +35,7 @@ class HttpRunner(object):
|
|||||||
testcases (list): parsed testcases list
|
testcases (list): parsed testcases list
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple: unittest.TestSuite()
|
unittest.TestSuite()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def _add_teststep(test_runner, config, teststep_dict):
|
def _add_teststep(test_runner, config, teststep_dict):
|
||||||
@@ -165,10 +153,7 @@ class HttpRunner(object):
|
|||||||
"variables": [], # optional
|
"variables": [], # optional
|
||||||
"request": {} # optional
|
"request": {} # optional
|
||||||
"refs": {
|
"refs": {
|
||||||
"debugtalk": {
|
"functions": {},
|
||||||
"variables": {},
|
|
||||||
"functions": {}
|
|
||||||
},
|
|
||||||
"env": {},
|
"env": {},
|
||||||
"def-api": {},
|
"def-api": {},
|
||||||
"def-testcase": {}
|
"def-testcase": {}
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ def substitute_variables(content, variables_mapping):
|
|||||||
|
|
||||||
return content
|
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.
|
""" parse parameters and generate cartesian product.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -265,7 +265,7 @@ def parse_parameters(parameters, variables_mapping, functions_mapping):
|
|||||||
(2) call built-in parameterize function, "${parameterize(account.csv)}"
|
(2) call built-in parameterize function, "${parameterize(account.csv)}"
|
||||||
(3) call custom function in debugtalk.py, "${gen_app_version()}"
|
(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
|
functions_mapping (dict): functions mapping loaded from debugtalk.py
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -280,7 +280,10 @@ def parse_parameters(parameters, variables_mapping, functions_mapping):
|
|||||||
>>> parse_parameters(parameters)
|
>>> parse_parameters(parameters)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
variables_mapping = variables_mapping or {}
|
||||||
|
functions_mapping = functions_mapping or {}
|
||||||
parsed_parameters_list = []
|
parsed_parameters_list = []
|
||||||
|
|
||||||
for parameter in parameters:
|
for parameter in parameters:
|
||||||
parameter_name, parameter_content = list(parameter.items())[0]
|
parameter_name, parameter_content = list(parameter.items())[0]
|
||||||
parameter_name_list = parameter_name.split("-")
|
parameter_name_list = parameter_name.split("-")
|
||||||
@@ -542,7 +545,7 @@ def parse_tests(testcases, variables_mapping=None):
|
|||||||
"config": {
|
"config": {
|
||||||
"name": "desc1",
|
"name": "desc1",
|
||||||
"path": "testcase1_path",
|
"path": "testcase1_path",
|
||||||
"variables": [], # optional
|
"variables": {}, # optional
|
||||||
"request": {} # optional
|
"request": {} # optional
|
||||||
"refs": {
|
"refs": {
|
||||||
"debugtalk": {
|
"debugtalk": {
|
||||||
@@ -598,7 +601,7 @@ def parse_tests(testcases, variables_mapping=None):
|
|||||||
config_parameters = testcase_config.pop("parameters", [])
|
config_parameters = testcase_config.pop("parameters", [])
|
||||||
cartesian_product_parameters_list = parse_parameters(
|
cartesian_product_parameters_list = parse_parameters(
|
||||||
config_parameters,
|
config_parameters,
|
||||||
{},
|
testcase_config.get("variables", {}),
|
||||||
project_mapping["functions"]
|
project_mapping["functions"]
|
||||||
) or [{}]
|
) or [{}]
|
||||||
|
|
||||||
|
|||||||
@@ -364,8 +364,7 @@ class TestParser(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
variables_mapping = {}
|
variables_mapping = {}
|
||||||
functions_mapping = {}
|
functions_mapping = {}
|
||||||
cartesian_product_parameters = parser.parse_parameters(
|
cartesian_product_parameters = parser.parse_parameters(parameters)
|
||||||
parameters, variables_mapping, functions_mapping)
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(cartesian_product_parameters),
|
len(cartesian_product_parameters),
|
||||||
3 * 2
|
3 * 2
|
||||||
@@ -389,11 +388,9 @@ class TestParser(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
loader.load_dot_env_file(dot_env_path)
|
loader.load_dot_env_file(dot_env_path)
|
||||||
from tests import debugtalk
|
from tests import debugtalk
|
||||||
functions = loader.load_module_functions(debugtalk)
|
|
||||||
cartesian_product_parameters = parser.parse_parameters(
|
cartesian_product_parameters = parser.parse_parameters(
|
||||||
parameters,
|
parameters,
|
||||||
{},
|
functions_mapping=loader.load_module_functions(debugtalk)
|
||||||
functions
|
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(cartesian_product_parameters),
|
len(cartesian_product_parameters),
|
||||||
@@ -405,11 +402,7 @@ class TestParser(unittest.TestCase):
|
|||||||
{"app_version": "${parameterize(tests/data/app_version.csv)}"},
|
{"app_version": "${parameterize(tests/data/app_version.csv)}"},
|
||||||
{"username-password": "${parameterize(tests/data/account.csv)}"}
|
{"username-password": "${parameterize(tests/data/account.csv)}"}
|
||||||
]
|
]
|
||||||
variables_mapping = {}
|
cartesian_product_parameters = parser.parse_parameters(parameters)
|
||||||
functions_mapping = {}
|
|
||||||
|
|
||||||
cartesian_product_parameters = parser.parse_parameters(
|
|
||||||
parameters, variables_mapping, functions_mapping)
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(cartesian_product_parameters),
|
len(cartesian_product_parameters),
|
||||||
2 * 3
|
2 * 3
|
||||||
@@ -424,13 +417,12 @@ class TestParser(unittest.TestCase):
|
|||||||
{"username-password": "${parameterize(tests/data/account.csv)}"}
|
{"username-password": "${parameterize(tests/data/account.csv)}"}
|
||||||
]
|
]
|
||||||
variables_mapping = {}
|
variables_mapping = {}
|
||||||
functions_mapping = project_mapping["functions"]
|
|
||||||
testcase_path = os.path.join(
|
testcase_path = os.path.join(
|
||||||
os.getcwd(),
|
os.getcwd(),
|
||||||
"tests/data/demo_parameters.yml"
|
"tests/data/demo_parameters.yml"
|
||||||
)
|
)
|
||||||
cartesian_product_parameters = parser.parse_parameters(
|
cartesian_product_parameters = parser.parse_parameters(
|
||||||
parameters, variables_mapping, functions_mapping)
|
parameters, functions_mapping=project_mapping["functions"])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(cartesian_product_parameters),
|
len(cartesian_product_parameters),
|
||||||
3 * 2 * 3
|
3 * 2 * 3
|
||||||
|
|||||||
Reference in New Issue
Block a user