update locusts with HttpRunner 2.0

This commit is contained in:
debugtalk
2018-11-23 17:14:43 +08:00
parent 24e6b408e4
commit 8f4500566d
7 changed files with 73 additions and 101 deletions

View File

@@ -661,71 +661,3 @@ def load_tests(path, dot_env_path=None):
tests_mapping["testcases"] = testcases_list
return tests_mapping
def load_locust_tests(path, dot_env_path=None):
""" load locust testcases
Args:
path (str): testcase/testsuite file path.
dot_env_path (str): specified .env file path
Returns:
dict: locust testcases with weight
{
"config": {...},
"tests": [
# weight 3
[teststep11],
[teststep11],
[teststep11],
# weight 2
[teststep21, teststep22],
[teststep21, teststep22]
]
}
"""
raw_testcase = load_file(path)
load_project_tests(path, dot_env_path)
config = {}
tests = []
for item in raw_testcase:
key, test_block = item.popitem()
if key == "config":
config.update(test_block)
elif key == "test":
teststep = load_teststep(test_block)
weight = test_block.get("weight", 1)
for _ in range(weight):
tests.append(teststep)
# parse config variables
raw_config_variables = config.get("variables", [])
config_variables = parser.parse_data(
raw_config_variables,
{},
project_mapping["functions"]
)
# parse config name
config["name"] = parser.parse_data(
config.get("name", ""),
config_variables,
project_mapping["functions"]
)
# parse config request
config["request"] = parser.parse_data(
config.get("request", {}),
config_variables,
project_mapping["functions"]
)
return {
"config": config,
"tests": tests
}