From 3dc5aa738b39b4693d393691d98054899ef5e5aa Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 8 Apr 2019 14:44:11 +0800 Subject: [PATCH] prepare_locust_tests: remove functions --- httprunner/api.py | 21 ++++++++------------- httprunner/templates/locustfile_template | 10 ++++------ tests/test_api.py | 7 +++---- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/httprunner/api.py b/httprunner/api.py index 0790939a..e7817d11 100644 --- a/httprunner/api.py +++ b/httprunner/api.py @@ -280,27 +280,22 @@ def prepare_locust_tests(path): path (str): testcase file path. Returns: - dict: locust tests data + list: locust tests data - { - "functions": {}, - "tests": [] - } + [ + testcase1_dict, + testcase2_dict + ] """ tests_mapping = loader.load_tests(path) parsed_tests_mapping = parser.parse_tests(tests_mapping) - functions = parsed_tests_mapping.get("project_mapping", {}).get("functions", {}) - - tests = [] + locust_tests = [] for testcase in parsed_tests_mapping["testcases"]: testcase_weight = testcase.get("config", {}).pop("weight", 1) for _ in range(testcase_weight): - tests.append(testcase) + locust_tests.append(testcase) - return { - "functions": functions, - "tests": tests - } + return locust_tests diff --git a/httprunner/templates/locustfile_template b/httprunner/templates/locustfile_template index f8d81b61..410a6fe5 100644 --- a/httprunner/templates/locustfile_template +++ b/httprunner/templates/locustfile_template @@ -15,7 +15,8 @@ logging.getLogger('locust.runners').setLevel(logging.INFO) class WebPageTasks(TaskSet): def on_start(self): - self.test_runner = Runner(self.locust.config, self.client) + config = {} + self.test_runner = Runner(config, self.client) @task def test_any(self): @@ -32,13 +33,10 @@ class WebPageTasks(TaskSet): class WebPageUser(HttpLocust): + host = "" task_set = WebPageTasks min_wait = 10 max_wait = 30 file_path = "$TESTCASE_FILE" - locust_tests = prepare_locust_tests(file_path) - tests = locust_tests["tests"] - config = {} - - host = config.get('base_url', '') + tests = prepare_locust_tests(file_path) diff --git a/tests/test_api.py b/tests/test_api.py index b969944e..78aba4ef 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -747,11 +747,10 @@ class TestLocust(unittest.TestCase): path = os.path.join( os.getcwd(), 'tests/locust_tests/demo_locusts.yml') locust_tests = prepare_locust_tests(path) - self.assertIn("gen_md5", locust_tests["functions"]) - self.assertEqual(len(locust_tests["tests"]), 2 + 3) + self.assertEqual(len(locust_tests), 2 + 3) name_list = [ "create user 1000 and check result.", "create user 1001 and check result." ] - self.assertIn(locust_tests["tests"][0]["config"]["name"], name_list) - self.assertIn(locust_tests["tests"][4]["config"]["name"], name_list) + self.assertIn(locust_tests[0]["config"]["name"], name_list) + self.assertIn(locust_tests[4]["config"]["name"], name_list)