prepare_locust_tests: remove functions

This commit is contained in:
debugtalk
2019-04-08 14:51:38 +08:00
parent 1c207e2dc4
commit 0ea0e828c9
3 changed files with 15 additions and 23 deletions
+8 -13
View File
@@ -280,27 +280,22 @@ def prepare_locust_tests(path):
path (str): testcase file path. path (str): testcase file path.
Returns: Returns:
dict: locust tests data list: locust tests data
{ [
"functions": {}, testcase1_dict,
"tests": [] testcase2_dict
} ]
""" """
tests_mapping = loader.load_tests(path) tests_mapping = loader.load_tests(path)
parsed_tests_mapping = parser.parse_tests(tests_mapping) parsed_tests_mapping = parser.parse_tests(tests_mapping)
functions = parsed_tests_mapping.get("project_mapping", {}).get("functions", {}) locust_tests = []
tests = []
for testcase in parsed_tests_mapping["testcases"]: for testcase in parsed_tests_mapping["testcases"]:
testcase_weight = testcase.get("config", {}).pop("weight", 1) testcase_weight = testcase.get("config", {}).pop("weight", 1)
for _ in range(testcase_weight): for _ in range(testcase_weight):
tests.append(testcase) locust_tests.append(testcase)
return { return locust_tests
"functions": functions,
"tests": tests
}
+4 -6
View File
@@ -15,7 +15,8 @@ logging.getLogger('locust.runners').setLevel(logging.INFO)
class WebPageTasks(TaskSet): class WebPageTasks(TaskSet):
def on_start(self): def on_start(self):
self.test_runner = Runner(self.locust.config, self.client) config = {}
self.test_runner = Runner(config, self.client)
@task @task
def test_any(self): def test_any(self):
@@ -32,13 +33,10 @@ class WebPageTasks(TaskSet):
class WebPageUser(HttpLocust): class WebPageUser(HttpLocust):
host = ""
task_set = WebPageTasks task_set = WebPageTasks
min_wait = 10 min_wait = 10
max_wait = 30 max_wait = 30
file_path = "$TESTCASE_FILE" file_path = "$TESTCASE_FILE"
locust_tests = prepare_locust_tests(file_path) tests = prepare_locust_tests(file_path)
tests = locust_tests["tests"]
config = {}
host = config.get('base_url', '')
+3 -4
View File
@@ -747,11 +747,10 @@ class TestLocust(unittest.TestCase):
path = os.path.join( path = os.path.join(
os.getcwd(), 'tests/locust_tests/demo_locusts.yml') os.getcwd(), 'tests/locust_tests/demo_locusts.yml')
locust_tests = prepare_locust_tests(path) locust_tests = prepare_locust_tests(path)
self.assertIn("gen_md5", locust_tests["functions"]) self.assertEqual(len(locust_tests), 2 + 3)
self.assertEqual(len(locust_tests["tests"]), 2 + 3)
name_list = [ name_list = [
"create user 1000 and check result.", "create user 1000 and check result.",
"create user 1001 and check result." "create user 1001 and check result."
] ]
self.assertIn(locust_tests["tests"][0]["config"]["name"], name_list) self.assertIn(locust_tests[0]["config"]["name"], name_list)
self.assertIn(locust_tests["tests"][4]["config"]["name"], name_list) self.assertIn(locust_tests[4]["config"]["name"], name_list)