mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
relocate functions
This commit is contained in:
@@ -3,7 +3,6 @@ import importlib
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import types
|
||||
from collections import OrderedDict
|
||||
|
||||
from ate import utils
|
||||
@@ -11,12 +10,6 @@ from ate.exception import ParamsError
|
||||
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):
|
||||
""" Manages context functions and variables.
|
||||
context has two levels, testset and testcase.
|
||||
@@ -77,8 +70,7 @@ class Context(object):
|
||||
"""
|
||||
sys.path.insert(0, os.getcwd())
|
||||
for module_name in modules:
|
||||
imported = importlib.import_module(module_name)
|
||||
imported_functions_dict = dict(filter(is_function, vars(imported).items()))
|
||||
imported_functions_dict = utils.get_module_functions(module_name)
|
||||
self.__update_context_functions_config(level, imported_functions_dict)
|
||||
|
||||
def bind_variables(self, variable_binds, level="testcase"):
|
||||
|
||||
15
ate/utils.py
15
ate/utils.py
@@ -2,11 +2,13 @@ import codecs
|
||||
import fnmatch
|
||||
import hashlib
|
||||
import hmac
|
||||
import importlib
|
||||
import json
|
||||
import os.path
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
import types
|
||||
|
||||
import yaml
|
||||
from ate import exception
|
||||
@@ -246,3 +248,16 @@ def deep_update_dict(origin_dict, override_dict):
|
||||
origin_dict[key] = override_dict[key]
|
||||
|
||||
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