From 7d5f6fa1786fc34040182fd75ae0d8b4ed527f27 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Sat, 4 Apr 2020 17:56:17 +0200 Subject: [PATCH] Remove setup and teardown hooks from Locust/Taskset (they will be replaced by events, since that makes much more sense) --- locust/core.py | 50 -------------------------------- locust/test/test_locust_class.py | 9 ------ 2 files changed, 59 deletions(-) diff --git a/locust/core.py b/locust/core.py index cca8507451..e4d62d2be8 100644 --- a/locust/core.py +++ b/locust/core.py @@ -5,8 +5,6 @@ from time import time import gevent -import gevent.lock - from gevent import GreenletExit, monkey # The monkey patching must run before requests is imported, or else @@ -207,10 +205,6 @@ class ForumPage(TaskSet): instantiated. Useful for nested TaskSet classes. """ - _setup_has_run = False # Internal state to see if we have already run - _teardown_is_set = False # Internal state to see if we have already run - _lock = gevent.lock.Semaphore() # Lock to make sure setup is only run once - def __init__(self, parent): # check if deprecated wait API is used deprecation.check_for_deprecated_wait_api(self) @@ -235,26 +229,6 @@ def __init__(self, parent): if not self.wait_function: self.wait_function = self.locust.wait_function - with self._lock: - if hasattr(self, "setup") and self._setup_has_run is False: - self._set_setup_flag() - try: - self.setup() - except Exception as e: - self.locust.environment.events.locust_error.fire(locust_instance=self, exception=e, tb=sys.exc_info()[2]) - logger.error("%s\n%s", e, traceback.format_exc()) - if hasattr(self, "teardown") and self._teardown_is_set is False: - self._set_teardown_flag() - self.environment.events.quitting.add_listener(self.teardown) - - @classmethod - def _set_setup_flag(cls): - cls._setup_has_run = True - - @classmethod - def _set_teardown_flag(cls): - cls._teardown_is_set = True - def on_start(self): """ Hook for end-user scripts for running code when a Locust user starts running @@ -538,9 +512,6 @@ class ForumPage(TaskSet): client = NoClientWarningRaiser() _catch_exceptions = True - _setup_has_run = False # Internal state to see if we have already run - _teardown_is_set = False # Internal state to see if we have already run - _lock = gevent.lock.Semaphore() # Lock to make sure setup is only run once _state = None _greenlet = None @@ -548,28 +519,7 @@ def __init__(self, environment): super(Locust, self).__init__() # check if deprecated wait API is used deprecation.check_for_deprecated_wait_api(self) - self.environment = environment - - with self._lock: - if hasattr(self, "setup") and self._setup_has_run is False: - self._set_setup_flag() - try: - self.setup() - except Exception as e: - self.environment.events.locust_error.fire(locust_instance=self, exception=e, tb=sys.exc_info()[2]) - logger.error("%s\n%s", e, traceback.format_exc()) - if hasattr(self, "teardown") and self._teardown_is_set is False: - self._set_teardown_flag() - self.environment.events.quitting.add_listener(self.teardown) - - @classmethod - def _set_setup_flag(cls): - cls._setup_has_run = True - - @classmethod - def _set_teardown_flag(cls): - cls._teardown_is_set = True def on_start(self): """ diff --git a/locust/test/test_locust_class.py b/locust/test/test_locust_class.py index 898d4b012d..042ae666be 100644 --- a/locust/test/test_locust_class.py +++ b/locust/test/test_locust_class.py @@ -430,15 +430,6 @@ class MyLocust(Locust): class TestLocustClass(LocustTestCase): - def test_setup_method(self): - class User(Locust): - setup_run_count = 0 - def setup(self): - User.setup_run_count += 1 - User(self.environment) - User(self.environment) - self.assertEqual(1, User.setup_run_count) - def test_locust_on_start(self): class MyLocust(Locust): t1_executed = False