简介:
httprunner是2018年推出的一款可以用于接口、性能测试的框架,该框架是在requests库、pytest框架和locust库进行的二次封装。
1.在httprunner库中的cli模块下可以看到:
import pytest ... def main_run(extra_args) -> enum.IntEnum: capture_message("start to run") # keep compatibility with v2 extra_args = ensure_cli_args(extra_args) tests_path_list = [] extra_args_new = [] for item in extra_args: if not os.path.exists(item): # item is not file/folder path extra_args_new.append(item) else: # item is file/folder path tests_path_list.append(item) if len(tests_path_list) == 0: # has not specified any testcase path logger.error(f"No valid testcase path in cli arguments: {extra_args}") sys.exit(1) testcase_path_list = main_make(tests_path_list) if not testcase_path_list: logger.error("No valid testcases found, exit 1.") sys.exit(1) if "--tb=short" not in extra_args_new: extra_args_new.append("--tb=short") extra_args_new.extend(testcase_path_list) logger.info(f"start to run tests with pytest. HttpRunner version: {__version__}") return pytest.main(extra_args_new)
2.在httprunner库中的client模块下可以看到
import requests
requests Request, Response requests.exceptions ( InvalidSchema, InvalidURL, MissingSchema, RequestException, )
。。。
HttpSession(requests.Session):
。。。
3.在httprunner库中ext目录中可以看见locust的python包,其中直接使用了locust库
random locust task, HttpUser, between httprunner.ext.locust prepare_locust_tests HttpRunnerUser(HttpUser): host = wait_time = between(, ) on_start(): locust_tests = prepare_locust_tests() .testcase_runners = [ testcase().with_session(.client) testcase locust_tests ] test_any(): test_runner = random.choice(.testcase_runners) : test_runner.run() ex: .environment.events.request_failure.fire( =, =test_runner.config.name, =, =, =ex, )