From c8dbc5cec3454391f3c2f4bfc102d74a98dd34e8 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 29 Jun 2020 11:06:19 +0800 Subject: [PATCH] fix: NameError, name 'locust_main' is not defined --- docs/CHANGELOG.md | 6 +++++- httprunner/ext/locust/__init__.py | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 669ae263..ec3fce4a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,12 +1,16 @@ # Release History -## 3.1.2 (2020-06-28) +## 3.1.2 (2020-06-29) **Fixed** - fix: missing setup/teardown hooks for referenced testcase - fix: compatibility for `black` on Android termux that does not support multiprocessing well +**Changed** + +- change: import locust at beginning to monkey patch all modules + ## 3.1.1 (2020-06-23) **Added** diff --git a/httprunner/ext/locust/__init__.py b/httprunner/ext/locust/__init__.py index fe528e68..38214567 100644 --- a/httprunner/ext/locust/__init__.py +++ b/httprunner/ext/locust/__init__.py @@ -1,16 +1,12 @@ -import importlib.util -import inspect -import os import sys -from typing import List -if sys.argv[0].endswith("locusts"): +if "locust" in sys.argv[0]: try: - # monkey patch ssl at beginning to avoid RecursionError when running locust. - from gevent import monkey - - monkey.patch_ssl() + # monkey patch all at beginning to avoid RecursionError when running locust. + # `from gevent import monkey; monkey.patch_all()` will be triggered when importing locust from locust import main as locust_main + + print("NOTICE: gevent monkey patches have been applied !!!") except ImportError: msg = """ Locust is not installed, install first and try again. @@ -20,9 +16,14 @@ $ pip install locust print(msg) sys.exit(1) +import importlib.util +import inspect +import os +from typing import List from loguru import logger + """ converted pytest files from YAML/JSON testcases """ pytest_files: List = []