mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 19:39:44 +08:00
refactor load_testcases function name
This commit is contained in:
@@ -236,7 +236,7 @@ def load_api_file(file_path):
|
||||
|
||||
|
||||
def load_test_file(file_path):
|
||||
""" load testcase file or suite file
|
||||
""" load testcase file or testsuite file
|
||||
@param file_path: absolute valid file path
|
||||
file_path should be in format below:
|
||||
[
|
||||
@@ -355,28 +355,28 @@ def _get_test_definition(name, ref_type):
|
||||
return block
|
||||
|
||||
|
||||
def load_testsets_by_path(path):
|
||||
def load_testcases(path):
|
||||
""" load testcases from file path
|
||||
@param path: path could be in several type
|
||||
- absolute/relative file path
|
||||
- absolute/relative folder path
|
||||
- list/set container with file(s) and/or folder(s)
|
||||
@return testcase sets list, each testset is corresponding to a file
|
||||
@return testcases list, each testcase is corresponding to a file
|
||||
[
|
||||
testset_dict_1,
|
||||
testset_dict_2
|
||||
testcase_dict_1,
|
||||
testcase_dict_2
|
||||
]
|
||||
"""
|
||||
if isinstance(path, (list, set)):
|
||||
testsets = []
|
||||
testcases_list = []
|
||||
|
||||
for file_path in set(path):
|
||||
testset = load_testsets_by_path(file_path)
|
||||
if not testset:
|
||||
testcases = load_testcases(file_path)
|
||||
if not testcases:
|
||||
continue
|
||||
testsets.extend(testset)
|
||||
testcases_list.extend(testcases)
|
||||
|
||||
return testsets
|
||||
return testcases_list
|
||||
|
||||
if not os.path.isabs(path):
|
||||
path = os.path.join(os.getcwd(), path)
|
||||
@@ -386,21 +386,22 @@ def load_testsets_by_path(path):
|
||||
|
||||
if os.path.isdir(path):
|
||||
files_list = load_folder_files(path)
|
||||
testcases_list = load_testsets_by_path(files_list)
|
||||
testcases_list = load_testcases(files_list)
|
||||
|
||||
elif os.path.isfile(path):
|
||||
try:
|
||||
testset = load_test_file(path)
|
||||
if testset["testcases"] or testset["api"]:
|
||||
testcases_list = [testset]
|
||||
testcase = load_test_file(path)
|
||||
if testcase["testcases"]:
|
||||
testcases_list = [testcase]
|
||||
else:
|
||||
testcases_list = []
|
||||
except exceptions.FileFormatError:
|
||||
testcases_list = []
|
||||
|
||||
else:
|
||||
logger.log_error(u"file not found: {}".format(path))
|
||||
testcases_list = []
|
||||
err_msg = "file not found: {}".format(path)
|
||||
logger.log_error(err_msg)
|
||||
raise exceptions.FileNotFound(err_msg)
|
||||
|
||||
testcases_cache_mapping[path] = testcases_list
|
||||
return testcases_list
|
||||
|
||||
@@ -179,7 +179,7 @@ def init_test_suites(path_or_testsets, mapping=None, http_client_session=None):
|
||||
"""
|
||||
if not testcase.is_testsets(path_or_testsets):
|
||||
loader.load_test_dependencies()
|
||||
testsets = loader.load_testsets_by_path(path_or_testsets)
|
||||
testsets = loader.load_testcases(path_or_testsets)
|
||||
else:
|
||||
testsets = path_or_testsets
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
# absolute file path
|
||||
path = os.path.join(
|
||||
os.getcwd(), 'tests/data/demo_testset_hardcode.json')
|
||||
testset_list = loader.load_testsets_by_path(path)
|
||||
testset_list = loader.load_testcases(path)
|
||||
self.assertEqual(len(testset_list), 1)
|
||||
self.assertIn("path", testset_list[0]["config"])
|
||||
self.assertEqual(testset_list[0]["config"]["path"], path)
|
||||
@@ -249,7 +249,7 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
|
||||
# relative file path
|
||||
path = 'tests/data/demo_testset_hardcode.yml'
|
||||
testset_list = loader.load_testsets_by_path(path)
|
||||
testset_list = loader.load_testcases(path)
|
||||
self.assertEqual(len(testset_list), 1)
|
||||
self.assertIn("path", testset_list[0]["config"])
|
||||
self.assertIn(path, testset_list[0]["config"]["path"])
|
||||
@@ -261,7 +261,7 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
os.path.join(os.getcwd(), 'tests/data/demo_testset_hardcode.json'),
|
||||
'tests/data/demo_testset_hardcode.yml'
|
||||
]
|
||||
testset_list = loader.load_testsets_by_path(path)
|
||||
testset_list = loader.load_testcases(path)
|
||||
self.assertEqual(len(testset_list), 2)
|
||||
self.assertEqual(len(testset_list[0]["testcases"]), 3)
|
||||
self.assertEqual(len(testset_list[1]["testcases"]), 3)
|
||||
@@ -279,12 +279,12 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
loader.load_test_dependencies()
|
||||
# absolute folder path
|
||||
path = os.path.join(os.getcwd(), 'tests/data')
|
||||
testset_list_1 = loader.load_testsets_by_path(path)
|
||||
testset_list_1 = loader.load_testcases(path)
|
||||
self.assertGreater(len(testset_list_1), 4)
|
||||
|
||||
# relative folder path
|
||||
path = 'tests/data/'
|
||||
testset_list_2 = loader.load_testsets_by_path(path)
|
||||
testset_list_2 = loader.load_testcases(path)
|
||||
self.assertEqual(len(testset_list_1), len(testset_list_2))
|
||||
|
||||
# list/set container with file(s)
|
||||
@@ -292,33 +292,33 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
os.path.join(os.getcwd(), 'tests/data'),
|
||||
'tests/data/'
|
||||
]
|
||||
testset_list_3 = loader.load_testsets_by_path(path)
|
||||
testset_list_3 = loader.load_testcases(path)
|
||||
self.assertEqual(len(testset_list_3), 2 * len(testset_list_1))
|
||||
|
||||
def test_load_testcases_by_path_not_exist(self):
|
||||
# absolute folder path
|
||||
path = os.path.join(os.getcwd(), 'tests/data_not_exist')
|
||||
testset_list_1 = loader.load_testsets_by_path(path)
|
||||
self.assertEqual(testset_list_1, [])
|
||||
with self.assertRaises(exceptions.FileNotFound):
|
||||
loader.load_testcases(path)
|
||||
|
||||
# relative folder path
|
||||
path = 'tests/data_not_exist'
|
||||
testset_list_2 = loader.load_testsets_by_path(path)
|
||||
self.assertEqual(testset_list_2, [])
|
||||
with self.assertRaises(exceptions.FileNotFound):
|
||||
loader.load_testcases(path)
|
||||
|
||||
# list/set container with file(s)
|
||||
path = [
|
||||
os.path.join(os.getcwd(), 'tests/data_not_exist'),
|
||||
'tests/data_not_exist/'
|
||||
]
|
||||
testset_list_3 = loader.load_testsets_by_path(path)
|
||||
self.assertEqual(testset_list_3, [])
|
||||
with self.assertRaises(exceptions.FileNotFound):
|
||||
loader.load_testcases(path)
|
||||
|
||||
def test_load_testcases_by_path_layered(self):
|
||||
loader.load_test_dependencies()
|
||||
path = os.path.join(
|
||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||
testsets_list = loader.load_testsets_by_path(path)
|
||||
testsets_list = loader.load_testcases(path)
|
||||
self.assertIn("variables", testsets_list[0]["config"])
|
||||
self.assertIn("request", testsets_list[0]["config"])
|
||||
self.assertIn("request", testsets_list[0]["testcases"][0])
|
||||
|
||||
@@ -380,7 +380,7 @@ class TestRunner(ApiServerUnittest):
|
||||
def test_run_testcase_with_empty_header(self):
|
||||
testcase_file_path = os.path.join(
|
||||
os.getcwd(), 'tests/data/test_bugfix.yml')
|
||||
testsets = loader.load_testsets_by_path(testcase_file_path)
|
||||
testsets = loader.load_testcases(testcase_file_path)
|
||||
testset = testsets[0]
|
||||
config_dict_headers = testset["config"]["request"]["headers"]
|
||||
test_dict_headers = testset["testcases"][0]["request"]["headers"]
|
||||
|
||||
Reference in New Issue
Block a user