mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-04 21:17:01 +08:00
replace filter_module with load_python_module
This commit is contained in:
@@ -5,7 +5,7 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from httprunner import built_in, exceptions, logger, parser, utils
|
||||
from httprunner import built_in, exceptions, loader, logger, parser, utils
|
||||
from httprunner.compat import OrderedDict
|
||||
|
||||
|
||||
@@ -69,11 +69,9 @@ class Context(object):
|
||||
def import_module_items(self, imported_module):
|
||||
""" import module functions and variables and bind to testset context
|
||||
"""
|
||||
imported_functions_dict = utils.filter_module(imported_module, "function")
|
||||
self.__update_context_functions_config("testset", imported_functions_dict)
|
||||
|
||||
imported_variables_dict = utils.filter_module(imported_module, "variable")
|
||||
self.bind_variables(imported_variables_dict, "testset")
|
||||
module_mapping = loader.load_python_module(imported_module)
|
||||
self.__update_context_functions_config("testset", module_mapping["functions"])
|
||||
self.bind_variables(module_mapping["variables"], "testset")
|
||||
|
||||
def bind_variables(self, variables, level="testcase"):
|
||||
""" bind variables to testset context or current testcase context.
|
||||
|
||||
@@ -207,6 +207,37 @@ def locate_debugtalk_py(start_path):
|
||||
return locate_debugtalk_py(os.path.dirname(start_dir_path))
|
||||
|
||||
|
||||
def load_python_module(module):
|
||||
""" load python module.
|
||||
|
||||
Args:
|
||||
module: python module
|
||||
|
||||
Returns:
|
||||
dict: variables and functions mapping for specified python module
|
||||
|
||||
{
|
||||
"variables": {},
|
||||
"functions": {}
|
||||
}
|
||||
|
||||
"""
|
||||
debugtalk_module = {
|
||||
"variables": {},
|
||||
"functions": {}
|
||||
}
|
||||
|
||||
for name, item in vars(module).items():
|
||||
if validator.is_function((name, item)):
|
||||
debugtalk_module["functions"][name] = item
|
||||
elif validator.is_variable((name, item)):
|
||||
debugtalk_module["variables"][name] = item
|
||||
else:
|
||||
pass
|
||||
|
||||
return debugtalk_module
|
||||
|
||||
|
||||
def load_debugtalk_module(start_path=None):
|
||||
""" load debugtalk.py module.
|
||||
|
||||
@@ -224,26 +255,17 @@ def load_debugtalk_module(start_path=None):
|
||||
|
||||
"""
|
||||
start_path = start_path or os.getcwd()
|
||||
debugtalk_module = {
|
||||
"variables": {},
|
||||
"functions": {}
|
||||
}
|
||||
|
||||
try:
|
||||
module_name = locate_debugtalk_py(start_path)
|
||||
except exceptions.FileNotFound:
|
||||
return debugtalk_module
|
||||
return {
|
||||
"variables": {},
|
||||
"functions": {}
|
||||
}
|
||||
|
||||
imported_module = importlib.import_module(module_name)
|
||||
for name, item in vars(imported_module).items():
|
||||
if validator.is_function((name, item)):
|
||||
debugtalk_module["functions"][name] = item
|
||||
elif validator.is_variable((name, item)):
|
||||
debugtalk_module["variables"][name] = item
|
||||
else:
|
||||
pass
|
||||
|
||||
return debugtalk_module
|
||||
return load_python_module(imported_module)
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
||||
Reference in New Issue
Block a user