mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
deprecate function_binds
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
__title__ = 'HttpRunner'
|
||||
__description__ = 'One-stop solution for HTTP(S) testing.'
|
||||
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
||||
__version__ = '1.5.7'
|
||||
__version__ = '1.5.8'
|
||||
__author__ = 'debugtalk'
|
||||
__author_email__ = 'mail@debugtalk.com'
|
||||
__license__ = 'MIT'
|
||||
|
||||
@@ -45,9 +45,6 @@ class Context(object):
|
||||
if level == "testset":
|
||||
self.testcase_parser.file_path = config_dict.get("path", None)
|
||||
|
||||
function_binds = config_dict.get('function_binds', {})
|
||||
self.bind_functions(function_binds, level)
|
||||
|
||||
variables = config_dict.get('variables') \
|
||||
or config_dict.get('variable_binds', OrderedDict())
|
||||
self.bind_variables(variables, level)
|
||||
|
||||
@@ -36,7 +36,6 @@ class Runner(object):
|
||||
{
|
||||
"name": "smoke testset",
|
||||
"path": "tests/data/demo_testset_variables.yml",
|
||||
"function_binds": {}, # optional
|
||||
"variables": [], # optional
|
||||
"request": {
|
||||
"base_url": "http://127.0.0.1:5000",
|
||||
@@ -48,7 +47,6 @@ class Runner(object):
|
||||
testcase:
|
||||
{
|
||||
"name": "testcase description",
|
||||
"function_binds": {}, # optional
|
||||
"variables": [], # optional
|
||||
"request": {
|
||||
"url": "/api/get-token",
|
||||
@@ -113,7 +111,6 @@ class Runner(object):
|
||||
"name": "testcase description",
|
||||
"skip": "skip this test unconditionally",
|
||||
"times": 3,
|
||||
"function_binds": {}, # optional, override
|
||||
"variables": [], # optional, override
|
||||
"request": {
|
||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||
|
||||
@@ -43,7 +43,6 @@ class TestSuite(unittest.TestSuite):
|
||||
"name": "testset description",
|
||||
"config": {
|
||||
"name": "testset description",
|
||||
"function_binds": {},
|
||||
"parameters": {},
|
||||
"variables": [],
|
||||
"request": {},
|
||||
|
||||
@@ -3,14 +3,6 @@ bind_variables:
|
||||
- TOKEN: "debugtalk"
|
||||
- token: $TOKEN
|
||||
|
||||
bind_lambda_functions:
|
||||
function_binds:
|
||||
add_one: "lambda x: x + 1"
|
||||
add_two_nums: "lambda x, y: x + y"
|
||||
variables:
|
||||
- add1: ${add_one(2)}
|
||||
- sum2nums: ${add_two_nums(2, 3)}
|
||||
|
||||
builtin_functions:
|
||||
variables:
|
||||
- length: ${len(debugtalk)}
|
||||
|
||||
@@ -76,30 +76,22 @@ class VariableBindsUnittest(ApiServerUnittest):
|
||||
self.assertEqual(testcase_variables["token"], "debugtalk")
|
||||
|
||||
def test_context_bind_lambda_functions(self):
|
||||
testcase1 = {
|
||||
"function_binds": {
|
||||
"add_one": lambda x: x + 1,
|
||||
"add_two_nums": lambda x, y: x + y
|
||||
},
|
||||
"variables": [
|
||||
{"add1": "${add_one(2)}"},
|
||||
{"sum2nums": "${add_two_nums(2,3)}"}
|
||||
]
|
||||
function_binds = {
|
||||
"add_one": lambda x: x + 1,
|
||||
"add_two_nums": lambda x, y: x + y
|
||||
}
|
||||
testcase2 = self.testcases["bind_lambda_functions"]
|
||||
variables = [
|
||||
{"add1": "${add_one(2)}"},
|
||||
{"sum2nums": "${add_two_nums(2,3)}"}
|
||||
]
|
||||
self.context.bind_functions(function_binds)
|
||||
self.context.bind_variables(variables)
|
||||
|
||||
for testcase in [testcase1, testcase2]:
|
||||
function_binds = testcase.get('function_binds', {})
|
||||
self.context.bind_functions(function_binds)
|
||||
|
||||
variables = testcase['variables']
|
||||
self.context.bind_variables(variables)
|
||||
|
||||
context_variables = self.context.testcase_variables_mapping
|
||||
self.assertIn("add1", context_variables)
|
||||
self.assertEqual(context_variables["add1"], 3)
|
||||
self.assertIn("sum2nums", context_variables)
|
||||
self.assertEqual(context_variables["sum2nums"], 5)
|
||||
context_variables = self.context.testcase_variables_mapping
|
||||
self.assertIn("add1", context_variables)
|
||||
self.assertEqual(context_variables["add1"], 3)
|
||||
self.assertIn("sum2nums", context_variables)
|
||||
self.assertEqual(context_variables["sum2nums"], 5)
|
||||
|
||||
def test_call_builtin_functions(self):
|
||||
testcase1 = {
|
||||
|
||||
Reference in New Issue
Block a user