mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-01 22:09:35 +08:00
add match filter to load_foler_files
This commit is contained in:
11
ate/utils.py
11
ate/utils.py
@@ -1,4 +1,5 @@
|
|||||||
import codecs
|
import codecs
|
||||||
|
import fnmatch
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
@@ -53,13 +54,17 @@ def load_testcases(testcase_file_path):
|
|||||||
# '' or other suffix
|
# '' or other suffix
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def load_foler_files(folder_path):
|
def load_foler_files(folder_path, match_filter_list=["*"]):
|
||||||
""" load folder path, return all files in list format.
|
""" load folder path, return all files in list format.
|
||||||
"""
|
"""
|
||||||
file_list = []
|
file_list = []
|
||||||
|
|
||||||
for dirpath, dirnames, filenames in os.walk(folder_path):
|
for dirpath, dirnames, filenames in os.walk(folder_path):
|
||||||
for filename in filenames:
|
filenames_list = []
|
||||||
|
for match_filter in match_filter_list:
|
||||||
|
filenames_list.extend(fnmatch.filter(filenames, match_filter))
|
||||||
|
|
||||||
|
for filename in filenames_list:
|
||||||
file_path = os.path.join(dirpath, filename)
|
file_path = os.path.join(dirpath, filename)
|
||||||
file_list.append(file_path)
|
file_list.append(file_path)
|
||||||
|
|
||||||
@@ -91,7 +96,7 @@ def load_testcases_by_path(path):
|
|||||||
path = os.path.join(os.getcwd(), path)
|
path = os.path.join(os.getcwd(), path)
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
files_list = load_foler_files(path)
|
files_list = load_foler_files(path, ["*.yml", "*.json"])
|
||||||
return load_testcases_by_path(files_list)
|
return load_testcases_by_path(files_list)
|
||||||
|
|
||||||
elif os.path.isfile(path):
|
elif os.path.isfile(path):
|
||||||
|
|||||||
@@ -33,11 +33,12 @@ class TestUtils(ApiServerUnittest):
|
|||||||
|
|
||||||
def test_load_foler_files(self):
|
def test_load_foler_files(self):
|
||||||
folder = os.path.join(os.getcwd(), 'tests')
|
folder = os.path.join(os.getcwd(), 'tests')
|
||||||
files = utils.load_foler_files(folder)
|
|
||||||
file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py')
|
file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py')
|
||||||
file2 = os.path.join(os.getcwd(), 'tests', 'data', 'demo_binds.yml')
|
file2 = os.path.join(os.getcwd(), 'tests', 'data', 'demo_binds.yml')
|
||||||
|
|
||||||
|
files = utils.load_foler_files(folder, ["*.py"])
|
||||||
self.assertIn(file1, files)
|
self.assertIn(file1, files)
|
||||||
self.assertIn(file2, files)
|
self.assertNotIn(file2, files)
|
||||||
|
|
||||||
def test_load_testcases_by_path_files(self):
|
def test_load_testcases_by_path_files(self):
|
||||||
testsets_list = []
|
testsets_list = []
|
||||||
|
|||||||
Reference in New Issue
Block a user