mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-05 15:59:33 +08:00
add load_testsuites_folder
This commit is contained in:
@@ -826,13 +826,13 @@ def load_api_folder(api_folder_path=None):
|
|||||||
return api_definition_mapping
|
return api_definition_mapping
|
||||||
|
|
||||||
|
|
||||||
def load_testcases_folder(testcases_folder_path=None):
|
def load_test_folder(test_folder_path=None, test_type="testcase"):
|
||||||
""" load testcases definitions from testcases folder.
|
""" load testcases/testsuites definitions from folder.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
testcases_folder_path (str): testcases files folder.
|
test_folder_path (str): testcases/testsuites files folder.
|
||||||
|
|
||||||
testcases file should be in the following format:
|
testcase file should be in the following format:
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
@@ -849,8 +849,25 @@ def load_testcases_folder(testcases_folder_path=None):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
testsuite file should be in the following format:
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"def": "create_and_check",
|
||||||
|
"request": {},
|
||||||
|
"validate": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test": {
|
||||||
|
"suite": "get_user", # TODO: repalce suite with testcase
|
||||||
|
"validate": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: testcases definition mapping.
|
dict: testcases/testsuites definition mapping.
|
||||||
|
|
||||||
{
|
{
|
||||||
"tests/testcases/setup.yml": [
|
"tests/testcases/setup.yml": [
|
||||||
@@ -866,41 +883,55 @@ def load_testcases_folder(testcases_folder_path=None):
|
|||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
testcases_definition_mapping = {}
|
test_definition_mapping = {}
|
||||||
|
|
||||||
# TODO: replace suite with testcases
|
if not test_folder_path:
|
||||||
testcases_folder_path = testcases_folder_path or os.path.join(os.getcwd(), "suite")
|
if test_type == "testcase":
|
||||||
testcases_items_mapping = load_folder_content(testcases_folder_path)
|
# TODO: replace suite with testcases
|
||||||
|
dir_name = "suite"
|
||||||
|
elif test_type == "testsuite":
|
||||||
|
# TODO: replace testcases with testsuites
|
||||||
|
dir_name = "testcases"
|
||||||
|
|
||||||
for testcase_file_path, testcase_items in testcases_items_mapping.items():
|
test_folder_path = os.path.join(os.getcwd(), dir_name)
|
||||||
|
|
||||||
|
test_items_mapping = load_folder_content(test_folder_path)
|
||||||
|
|
||||||
|
for test_file_path, items in test_items_mapping.items():
|
||||||
# TODO: add JSON schema validation
|
# TODO: add JSON schema validation
|
||||||
|
|
||||||
testcase = {
|
testcase = {
|
||||||
"config": {
|
"config": {
|
||||||
"path": testcase_file_path
|
"path": test_file_path
|
||||||
},
|
},
|
||||||
"tests": []
|
"tests": []
|
||||||
}
|
}
|
||||||
for item in testcase_items:
|
for item in items:
|
||||||
key, test_block = item.popitem()
|
key, block = item.popitem()
|
||||||
|
|
||||||
if key == "config":
|
if key == "config":
|
||||||
testcase["config"].update(test_block)
|
testcase["config"].update(block)
|
||||||
testcase_def = test_block.pop("def")
|
|
||||||
|
if "def" not in block:
|
||||||
|
# testsuite
|
||||||
|
test_definition_mapping[test_file_path] = testcase
|
||||||
|
continue
|
||||||
|
|
||||||
|
# testcase
|
||||||
|
testcase_def = block.pop("def")
|
||||||
function_meta = parser.parse_function(testcase_def)
|
function_meta = parser.parse_function(testcase_def)
|
||||||
func_name = function_meta["func_name"]
|
func_name = function_meta["func_name"]
|
||||||
|
|
||||||
if func_name in testcases_definition_mapping:
|
if func_name in test_definition_mapping:
|
||||||
logger.log_warning("API definition duplicated: {}".format(func_name))
|
logger.log_warning("API definition duplicated: {}".format(func_name))
|
||||||
|
|
||||||
test_block["function_meta"] = function_meta
|
block["function_meta"] = function_meta
|
||||||
testcases_definition_mapping[func_name] = testcase
|
test_definition_mapping[func_name] = testcase
|
||||||
else:
|
else:
|
||||||
# key == "test":
|
# key == "test":
|
||||||
testcase["tests"].append(test_block)
|
testcase["tests"].append(block)
|
||||||
|
|
||||||
return testcases_definition_mapping
|
|
||||||
|
|
||||||
|
return test_definition_mapping
|
||||||
|
|
||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ class TestSuiteLoader(unittest.TestCase):
|
|||||||
|
|
||||||
def test_load_testcases_folder(self):
|
def test_load_testcases_folder(self):
|
||||||
path = os.path.join(os.getcwd(), "tests", "suite")
|
path = os.path.join(os.getcwd(), "tests", "suite")
|
||||||
testcases_definition_mapping = loader.load_testcases_folder(path)
|
testcases_definition_mapping = loader.load_test_folder(path)
|
||||||
|
|
||||||
self.assertIn("setup_and_reset", testcases_definition_mapping)
|
self.assertIn("setup_and_reset", testcases_definition_mapping)
|
||||||
self.assertIn("create_and_check", testcases_definition_mapping)
|
self.assertIn("create_and_check", testcases_definition_mapping)
|
||||||
@@ -481,3 +481,17 @@ class TestSuiteLoader(unittest.TestCase):
|
|||||||
testcases_definition_mapping["setup_and_reset"]["config"]["name"],
|
testcases_definition_mapping["setup_and_reset"]["config"]["name"],
|
||||||
"setup and reset all."
|
"setup and reset all."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_load_testsuites_folder(self):
|
||||||
|
path = os.path.join(os.getcwd(), "tests", "testcases")
|
||||||
|
testsuites_definition_mapping = loader.load_test_folder(path)
|
||||||
|
|
||||||
|
testsute_path = os.path.join(os.getcwd(), "tests", "testcases", "smoketest.yml")
|
||||||
|
self.assertIn(
|
||||||
|
testsute_path,
|
||||||
|
testsuites_definition_mapping
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
testsuites_definition_mapping[testsute_path]["config"]["name"],
|
||||||
|
"smoketest"
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user