fix: check if locustio installed

This commit is contained in:
debugtalk
2020-04-12 23:58:10 +08:00
parent ade7935e4e
commit caa9503df8
2 changed files with 13 additions and 12 deletions

View File

@@ -29,6 +29,17 @@ def init_parser_locusts(subparsers):
def main_locusts(args, extra_args): def main_locusts(args, extra_args):
""" Performance test with locust: parse command line options and run commands. """ Performance test with locust: parse command line options and run commands.
""" """
try:
from locust.main import main
except ImportError:
msg = """
Locust is not installed, install first and try again.
install with pip:
$ pip install locustio
"""
logger.error(msg)
sys.exit(1)
logger.info(f"HttpRunner version: {__version__}") logger.info(f"HttpRunner version: {__version__}")
sys.argv = ["locust", *extra_args] sys.argv = ["locust", *extra_args]

View File

@@ -5,17 +5,6 @@ import sys
from loguru import logger from loguru import logger
try:
from locust import main as locust_main
except ImportError:
msg = """
Locust is not installed, install first and try again.
install with pip:
$ pip install locustio
"""
logger.error(msg)
sys.exit(0)
def parse_locustfile(file_path): def parse_locustfile(file_path):
""" parse testcase file and return locustfile path. """ parse testcase file and return locustfile path.
@@ -59,7 +48,8 @@ def gen_locustfile(testcase_file_path):
def start_locust_main(): def start_locust_main():
logger.info(f"run command: {sys.argv}") logger.info(f"run command: {sys.argv}")
locust_main.main() from locust.main import main
main()
def start_master(sys_argv): def start_master(sys_argv):