mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 11:29:48 +08:00
LazyFunction: wrap argument
This commit is contained in:
@@ -117,16 +117,16 @@ class SessionContext(object):
|
||||
"validator should be parsed first: {}".format(validators))
|
||||
|
||||
# evaluate validator args with context variable mapping.
|
||||
validator_args = validator._args
|
||||
validator_args = validator.get_args()
|
||||
check_item, expect_item = validator_args
|
||||
check_value = self.__eval_validator_check(
|
||||
check_item,
|
||||
resp_obj
|
||||
)
|
||||
expect_value = self.__eval_validator_expect(expect_item)
|
||||
validator._args = [check_value, expect_value]
|
||||
validator.update_args([check_value, expect_value])
|
||||
|
||||
comparator = validator._func.__name__
|
||||
comparator = validator.func_name
|
||||
validator_dict = {
|
||||
"comparator": comparator,
|
||||
"check": check_item,
|
||||
@@ -163,7 +163,7 @@ class SessionContext(object):
|
||||
self.validation_results.append(validator_dict)
|
||||
|
||||
# restore validator args, in case of running multiple times
|
||||
validator._args = validator_args
|
||||
validator.update_args(validator_args)
|
||||
|
||||
if not validate_pass:
|
||||
failures_string = "\n".join([failure for failure in failures])
|
||||
|
||||
@@ -348,6 +348,7 @@ class LazyFunction(object):
|
||||
function_meta["func_name"],
|
||||
self.functions_mapping
|
||||
)
|
||||
self.func_name = self._func.__name__
|
||||
self._args = prepare_lazy_data(
|
||||
function_meta.get("args", []),
|
||||
self.functions_mapping,
|
||||
@@ -359,15 +360,21 @@ class LazyFunction(object):
|
||||
self.check_variables_set
|
||||
)
|
||||
|
||||
if self._func.__name__ == "load_csv_file":
|
||||
if self.func_name == "load_csv_file":
|
||||
if len(self._args) != 1 or self._kwargs:
|
||||
raise exceptions.ParamsError("P() should only pass in one argument!")
|
||||
self._args = [self._args[0]]
|
||||
elif self._func.__name__ == "get_os_environ":
|
||||
elif self.func_name == "get_os_environ":
|
||||
if len(self._args) != 1 or self._kwargs:
|
||||
raise exceptions.ParamsError("ENV() should only pass in one argument!")
|
||||
self._args = [self._args[0]]
|
||||
|
||||
def get_args(self):
|
||||
return self._args
|
||||
|
||||
def update_args(self, args):
|
||||
self._args = args
|
||||
|
||||
def __repr__(self):
|
||||
args_string = ""
|
||||
|
||||
@@ -383,10 +390,10 @@ class LazyFunction(object):
|
||||
]
|
||||
args_string += ", ".join(str_kwargs)
|
||||
|
||||
return "LazyFunction({}({}))".format(self._func.__name__, args_string)
|
||||
return "LazyFunction({}({}))".format(self.func_name, args_string)
|
||||
|
||||
def __prepare_cache_key(self, args, kwargs):
|
||||
return (self._func.__name__, repr(args), repr(kwargs))
|
||||
return (self.func_name, repr(args), repr(kwargs))
|
||||
|
||||
def to_value(self, variables_mapping=None):
|
||||
""" parse lazy data with evaluated variables mapping.
|
||||
|
||||
Reference in New Issue
Block a user