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