mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
add load_testcases_folder
This commit is contained in:
@@ -754,6 +754,7 @@ def load_folder_content(folder_path):
|
|||||||
{"api": {"def": "api_logout", "request": {}, "validate": []}}
|
{"api": {"def": "api_logout", "request": {}, "validate": []}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
items_mapping = {}
|
items_mapping = {}
|
||||||
|
|
||||||
@@ -800,6 +801,7 @@ def load_api_folder(api_folder_path=None):
|
|||||||
"request": {}
|
"request": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
api_definition_mapping = {}
|
api_definition_mapping = {}
|
||||||
|
|
||||||
@@ -824,6 +826,83 @@ def load_api_folder(api_folder_path=None):
|
|||||||
return api_definition_mapping
|
return api_definition_mapping
|
||||||
|
|
||||||
|
|
||||||
|
def load_testcases_folder(testcases_folder_path=None):
|
||||||
|
""" load testcases definitions from testcases folder.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
testcases_folder_path (str): testcases files folder.
|
||||||
|
|
||||||
|
testcases file should be in the following format:
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"def": "create_and_check",
|
||||||
|
"request": {},
|
||||||
|
"validate": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test": {
|
||||||
|
"api": "get_user",
|
||||||
|
"validate": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: testcases definition mapping.
|
||||||
|
|
||||||
|
{
|
||||||
|
"tests/testcases/setup.yml": [
|
||||||
|
{"config": {}},
|
||||||
|
{"test": {}},
|
||||||
|
{"test": {}}
|
||||||
|
],
|
||||||
|
"tests/testcases/create_and_get.yml": [
|
||||||
|
{"config": {}},
|
||||||
|
{"test": {}},
|
||||||
|
{"test": {}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
testcases_definition_mapping = {}
|
||||||
|
|
||||||
|
# TODO: replace suite with testcases
|
||||||
|
testcases_folder_path = testcases_folder_path or os.path.join(os.getcwd(), "suite")
|
||||||
|
testcases_items_mapping = load_folder_content(testcases_folder_path)
|
||||||
|
|
||||||
|
for testcase_file_path, testcase_items in testcases_items_mapping.items():
|
||||||
|
# TODO: add JSON schema validation
|
||||||
|
|
||||||
|
testcase = {
|
||||||
|
"config": {
|
||||||
|
"path": testcase_file_path
|
||||||
|
},
|
||||||
|
"tests": []
|
||||||
|
}
|
||||||
|
for item in testcase_items:
|
||||||
|
key, test_block = item.popitem()
|
||||||
|
|
||||||
|
if key == "config":
|
||||||
|
testcase["config"].update(test_block)
|
||||||
|
testcase_def = test_block.pop("def")
|
||||||
|
function_meta = parser.parse_function(testcase_def)
|
||||||
|
func_name = function_meta["func_name"]
|
||||||
|
|
||||||
|
if func_name in testcases_definition_mapping:
|
||||||
|
logger.log_warning("API definition duplicated: {}".format(func_name))
|
||||||
|
|
||||||
|
test_block["function_meta"] = function_meta
|
||||||
|
testcases_definition_mapping[func_name] = testcase
|
||||||
|
else:
|
||||||
|
# key == "test":
|
||||||
|
testcase["tests"].append(test_block)
|
||||||
|
|
||||||
|
return testcases_definition_mapping
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
""" main interface for loading testcases
|
""" main interface for loading testcases
|
||||||
|
|
||||||
|
|||||||
@@ -470,3 +470,14 @@ class TestSuiteLoader(unittest.TestCase):
|
|||||||
self.assertIn("get_token", api_definition_mapping)
|
self.assertIn("get_token", api_definition_mapping)
|
||||||
self.assertIn("request", api_definition_mapping["get_token"])
|
self.assertIn("request", api_definition_mapping["get_token"])
|
||||||
self.assertIn("function_meta", api_definition_mapping["get_token"])
|
self.assertIn("function_meta", api_definition_mapping["get_token"])
|
||||||
|
|
||||||
|
def test_load_testcases_folder(self):
|
||||||
|
path = os.path.join(os.getcwd(), "tests", "suite")
|
||||||
|
testcases_definition_mapping = loader.load_testcases_folder(path)
|
||||||
|
|
||||||
|
self.assertIn("setup_and_reset", testcases_definition_mapping)
|
||||||
|
self.assertIn("create_and_check", testcases_definition_mapping)
|
||||||
|
self.assertEqual(
|
||||||
|
testcases_definition_mapping["setup_and_reset"]["config"]["name"],
|
||||||
|
"setup and reset all."
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user