mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-27 11:20:08 +08:00
add hook feature:
1, setup_hook: call function before request 2, teardown_hook: call function after request
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from httprunner.client import HttpSession, prepare_kwargs
|
||||
from httprunner.built_in import setup_hook_prepare_kwargs
|
||||
from httprunner.client import HttpSession
|
||||
from tests.base import ApiServerUnittest
|
||||
|
||||
|
||||
class TestHttpClient(ApiServerUnittest):
|
||||
def setUp(self):
|
||||
super(TestHttpClient, self).setUp()
|
||||
@@ -46,7 +48,7 @@ class TestHttpClient(ApiServerUnittest):
|
||||
"b": 2
|
||||
}
|
||||
}
|
||||
prepare_kwargs("POST", kwargs)
|
||||
setup_hook_prepare_kwargs("POST", "/path", kwargs)
|
||||
self.assertIn('"a": 1', kwargs["data"])
|
||||
self.assertIn('"b": 2', kwargs["data"])
|
||||
|
||||
@@ -60,5 +62,5 @@ class TestHttpClient(ApiServerUnittest):
|
||||
"b": 2
|
||||
}
|
||||
}
|
||||
prepare_kwargs("POST", kwargs)
|
||||
setup_hook_prepare_kwargs("POST", "/path", kwargs)
|
||||
self.assertIsInstance(kwargs["data"], bytes)
|
||||
|
||||
@@ -230,7 +230,7 @@ class VariableBindsUnittest(ApiServerUnittest):
|
||||
|
||||
def test_exec_content_functions(self):
|
||||
test_runner = runner.Runner()
|
||||
content = "${sleep(1)}"
|
||||
content = "${teardown_hook_sleep_1_secs(1)}"
|
||||
start_time = time.time()
|
||||
test_runner.context.eval_content(content)
|
||||
end_time = time.time()
|
||||
|
||||
@@ -65,7 +65,7 @@ class TestRunner(ApiServerUnittest):
|
||||
{"check": "status_code", "expect": 205},
|
||||
{"check": "content.token", "comparator": "len_eq", "expect": 19}
|
||||
],
|
||||
"teardown": ["${sleep(2)}"]
|
||||
"teardown_hooks": ["teardown_hook_sleep_1_secs"]
|
||||
}
|
||||
|
||||
with self.assertRaises(exception.ValidationError):
|
||||
|
||||
Reference in New Issue
Block a user