mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 07:57:27 +08:00
relocate functions
This commit is contained in:
+1
-9
@@ -3,7 +3,6 @@ import importlib
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import types
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from ate import utils
|
from ate import utils
|
||||||
@@ -11,12 +10,6 @@ from ate.exception import ParamsError
|
|||||||
from ate.testcase import TestcaseParser
|
from ate.testcase import TestcaseParser
|
||||||
|
|
||||||
|
|
||||||
def is_function(tup):
|
|
||||||
""" Takes (name, object) tuple, returns True if it is a function.
|
|
||||||
"""
|
|
||||||
name, item = tup
|
|
||||||
return isinstance(item, types.FunctionType)
|
|
||||||
|
|
||||||
class Context(object):
|
class Context(object):
|
||||||
""" Manages context functions and variables.
|
""" Manages context functions and variables.
|
||||||
context has two levels, testset and testcase.
|
context has two levels, testset and testcase.
|
||||||
@@ -77,8 +70,7 @@ class Context(object):
|
|||||||
"""
|
"""
|
||||||
sys.path.insert(0, os.getcwd())
|
sys.path.insert(0, os.getcwd())
|
||||||
for module_name in modules:
|
for module_name in modules:
|
||||||
imported = importlib.import_module(module_name)
|
imported_functions_dict = utils.get_module_functions(module_name)
|
||||||
imported_functions_dict = dict(filter(is_function, vars(imported).items()))
|
|
||||||
self.__update_context_functions_config(level, imported_functions_dict)
|
self.__update_context_functions_config(level, imported_functions_dict)
|
||||||
|
|
||||||
def bind_variables(self, variable_binds, level="testcase"):
|
def bind_variables(self, variable_binds, level="testcase"):
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ import codecs
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
|
import importlib
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
import types
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from ate import exception
|
from ate import exception
|
||||||
@@ -246,3 +248,16 @@ def deep_update_dict(origin_dict, override_dict):
|
|||||||
origin_dict[key] = override_dict[key]
|
origin_dict[key] = override_dict[key]
|
||||||
|
|
||||||
return origin_dict
|
return origin_dict
|
||||||
|
|
||||||
|
def is_function(tup):
|
||||||
|
""" Takes (name, object) tuple, returns True if it is a function.
|
||||||
|
"""
|
||||||
|
name, item = tup
|
||||||
|
return isinstance(item, types.FunctionType)
|
||||||
|
|
||||||
|
def get_module_functions(module_name):
|
||||||
|
""" import module and return filtered functions
|
||||||
|
"""
|
||||||
|
imported = importlib.import_module(module_name)
|
||||||
|
module_functions_dict = dict(filter(is_function, vars(imported).items()))
|
||||||
|
return module_functions_dict
|
||||||
|
|||||||
Reference in New Issue
Block a user