From 17d2c176e8467d9c68f369746ba4f5f15c2e8f47 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Wed, 15 Apr 2020 12:43:56 +0200 Subject: [PATCH 1/2] Stop exposing InterruptTaskSet, ResponseError and RescheduleTaskImmediately on locust module (get them from locust.exception instead) --- locust/__init__.py | 1 - locust/test/test_locust_class.py | 2 +- locust/test/test_old_wait_api.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/locust/__init__.py b/locust/__init__.py index 8f25b82bf5..8741e5a3f9 100644 --- a/locust/__init__.py +++ b/locust/__init__.py @@ -1,6 +1,5 @@ from .core import HttpLocust, Locust, TaskSet, task from .event import Events -from .exception import InterruptTaskSet, ResponseError, RescheduleTaskImmediately from .sequential_taskset import SequentialTaskSet from .wait_time import between, constant, constant_pacing diff --git a/locust/test/test_locust_class.py b/locust/test/test_locust_class.py index fc9ceb8114..d97a6fd3ea 100644 --- a/locust/test/test_locust_class.py +++ b/locust/test/test_locust_class.py @@ -2,7 +2,7 @@ from gevent import sleep from gevent.pool import Group -from locust import InterruptTaskSet, ResponseError +from locust.exception import InterruptTaskSet, ResponseError from locust.core import HttpLocust, Locust, TaskSet, task from locust.env import Environment from locust.exception import (CatchResponseError, LocustError, RescheduleTask, diff --git a/locust/test/test_old_wait_api.py b/locust/test/test_old_wait_api.py index 57a6e2386d..ced8a224b4 100644 --- a/locust/test/test_old_wait_api.py +++ b/locust/test/test_old_wait_api.py @@ -1,6 +1,6 @@ import warnings -from locust import InterruptTaskSet, ResponseError +from locust.exception import InterruptTaskSet, ResponseError from locust.core import HttpLocust, Locust, TaskSet, task from locust.exception import (CatchResponseError, LocustError, RescheduleTask, RescheduleTaskImmediately) From e7e4f3282bd0cdbb89e98032e7647855a6153b8a Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Wed, 15 Apr 2020 13:03:22 +0200 Subject: [PATCH 2/2] Remove old wait api (and its deprecation warning) --- locust/core.py | 7 +- locust/test/test_old_wait_api.py | 106 ------------------------------- locust/util/deprecation.py | 24 ------- 3 files changed, 1 insertion(+), 136 deletions(-) delete mode 100644 locust/test/test_old_wait_api.py diff --git a/locust/core.py b/locust/core.py index bc068684bf..a515c5248f 100644 --- a/locust/core.py +++ b/locust/core.py @@ -176,10 +176,7 @@ class ForumPage(TaskSet): instantiated. Useful for nested TaskSet classes. """ - def __init__(self, parent): - # check if deprecated wait API is used - deprecation.check_for_deprecated_wait_api(self) - + def __init__(self, parent): self._task_queue = [] self._time_start = time() @@ -465,8 +462,6 @@ class ForumPage(TaskSet): 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 def on_start(self): diff --git a/locust/test/test_old_wait_api.py b/locust/test/test_old_wait_api.py deleted file mode 100644 index ced8a224b4..0000000000 --- a/locust/test/test_old_wait_api.py +++ /dev/null @@ -1,106 +0,0 @@ -import warnings - -from locust.exception import InterruptTaskSet, ResponseError -from locust.core import HttpLocust, Locust, TaskSet, task -from locust.exception import (CatchResponseError, LocustError, RescheduleTask, - RescheduleTaskImmediately) -from locust.wait_time import between, constant - -from .testcases import LocustTestCase, WebserverTestCase - - -class TestOldWaitApi(LocustTestCase): - def setUp(self): - super(TestOldWaitApi, self).setUp() - - def test_wait_function(self): - with warnings.catch_warnings(record=True) as w: - class User(Locust): - wait_function = lambda self: 5000 - class MyTaskSet(TaskSet): - pass - taskset = MyTaskSet(User(self.environment)) - self.assertEqual(5, taskset.wait_time()) - self.assertEqual(1, len(w)) - self.assertTrue(issubclass(w[0].category, DeprecationWarning)) - self.assertIn("wait_function", str(w[0].message)) - - def test_wait_function_on_taskset(self): - with warnings.catch_warnings(record=True) as w: - class User(Locust): - pass - class MyTaskSet(TaskSet): - wait_function = lambda self: 5000 - taskset = MyTaskSet(User(self.environment)) - self.assertEqual(5, taskset.wait_time()) - self.assertEqual(1, len(w)) - self.assertTrue(issubclass(w[0].category, DeprecationWarning)) - self.assertIn("wait_function", str(w[0].message)) - - def test_min_max_wait(self): - with warnings.catch_warnings(record=True) as w: - class User(Locust): - min_wait = 1000 - max_wait = 1000 - class TS(TaskSet): - @task - def t(self): - pass - taskset = TS(User(self.environment)) - self.assertEqual(1, taskset.wait_time()) - self.assertEqual(1, len(w)) - self.assertTrue(issubclass(w[0].category, DeprecationWarning)) - self.assertIn("min_wait", str(w[0].message)) - self.assertIn("max_wait", str(w[0].message)) - - def test_zero_min_max_wait(self): - return - with warnings.catch_warnings(record=True) as w: - class User(Locust): - min_wait = 0 - max_wait = 0 - class TS(TaskSet): - @task - def t(self): - pass - taskset = TS(User(self.environment)) - self.assertEqual(0, taskset.wait_time()) - self.assertEqual(1, len(w)) - self.assertTrue(issubclass(w[0].category, DeprecationWarning)) - self.assertIn("min_wait", str(w[0].message)) - self.assertIn("max_wait", str(w[0].message)) - - def test_min_max_wait_combined_with_wait_time(self): - with warnings.catch_warnings(record=True) as w: - class User(Locust): - min_wait = 1000 - max_wait = 1000 - class TS(TaskSet): - wait_time = constant(3) - @task - def t(self): - pass - taskset = TS(User(self.environment)) - self.assertEqual(3, taskset.wait_time()) - self.assertEqual(1, len(w)) - self.assertTrue(issubclass(w[0].category, DeprecationWarning)) - self.assertIn("min_wait", str(w[0].message)) - self.assertIn("max_wait", str(w[0].message)) - - def test_min_max_wait_on_taskset(self): - with warnings.catch_warnings(record=True) as w: - class User(Locust): - wait_time = constant(3) - class TS(TaskSet): - min_wait = 1000 - max_wait = 1000 - @task - def t(self): - pass - taskset = TS(User(self.environment)) - self.assertEqual(3, taskset.wait_time()) - self.assertEqual(1, len(w)) - self.assertTrue(issubclass(w[0].category, DeprecationWarning)) - self.assertIn("min_wait", str(w[0].message)) - self.assertIn("max_wait", str(w[0].message)) - diff --git a/locust/util/deprecation.py b/locust/util/deprecation.py index 9526ecb7d5..3e6b6ce98a 100644 --- a/locust/util/deprecation.py +++ b/locust/util/deprecation.py @@ -5,30 +5,6 @@ warnings.filterwarnings('always', category=DeprecationWarning, module="locust") -def check_for_deprecated_wait_api(locust_or_taskset): - # check if deprecated wait API is used - if locust_or_taskset.wait_function: - warnings.warn("Usage of wait_function is deprecated since version 0.13. Declare a %s.wait_time method instead " - "(should return seconds and not milliseconds)" % type(locust_or_taskset).__name__, DeprecationWarning) - from locust.core import TaskSet - if not locust_or_taskset.wait_time or locust_or_taskset.wait_time.__func__ == TaskSet.wait_time: - # If wait_function has been declared, and custom wait_time has NOT been declared, - # we'll add a wait_time function that just calls wait_function and divides the - # returned value by 1000.0 - locust_or_taskset.wait_time = lambda: locust_or_taskset.wait_function() / 1000.0 - if locust_or_taskset.min_wait is not None and locust_or_taskset.max_wait is not None: - def format_min_max_wait(i): - float_value = i / 1000.0 - if float_value == int(float_value): - return "%i" % int(float_value) - else: - return "%.3f" % float_value - warnings.warn("Usage of min_wait and max_wait is deprecated since version 0.13. Instead use: wait_time = between(%s, %s)" % ( - format_min_max_wait(locust_or_taskset.min_wait), - format_min_max_wait(locust_or_taskset.max_wait), - ), DeprecationWarning) - - def check_for_deprecated_task_set_attribute(class_dict): from locust.core import TaskSet if "task_set" in class_dict: