From cb44fafebf58d93ae8fa3ac823eff03ee52de9bc Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 23 Aug 2018 16:11:26 +0800 Subject: [PATCH] fix #189: remove file path dependency --- httprunner/api.py | 10 +++++----- httprunner/loader.py | 16 ++++++---------- httprunner/runner.py | 1 - httprunner/validator.py | 1 - tests/test_api.py | 9 +++------ tests/test_loader.py | 5 ----- tests/test_runner.py | 14 +++----------- 7 files changed, 17 insertions(+), 39 deletions(-) diff --git a/httprunner/api.py b/httprunner/api.py index 76d2eebc..2e87c5fe 100644 --- a/httprunner/api.py +++ b/httprunner/api.py @@ -52,7 +52,7 @@ class HttpRunner(object): { "config": { "name": "desc1", - "path": "", + "path": "", # optional "variables": [], # optional "request": {} # optional }, @@ -79,15 +79,15 @@ class HttpRunner(object): for testcase in path_or_testcases: try: test_path = os.path.dirname(testcase["config"]["path"]) - loader.load_project_tests(test_path) except KeyError: - pass + test_path = os.getcwd() + loader.load_project_tests(test_path) else: try: test_path = os.path.dirname(path_or_testcases["config"]["path"]) - loader.load_project_tests(test_path) except KeyError: - pass + test_path = os.getcwd() + loader.load_project_tests(test_path) testcases = path_or_testcases else: diff --git a/httprunner/loader.py b/httprunner/loader.py index a073d05c..5aa1de9f 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -424,9 +424,7 @@ def _load_test_file(file_path): """ testcase = { - "config": { - "path": file_path - }, + "config": {}, "teststeps": [] } @@ -856,9 +854,7 @@ def load_test_folder(test_folder_path): # TODO: add JSON schema validation testcase = { - "config": { - "path": test_file_path - }, + "config": {}, "teststeps": [] } for item in items: @@ -914,12 +910,12 @@ def load_project_tests(test_path): """ reset_loader() locate_pwd(test_path) - load_builtin_module() - load_api_folder(os.path.join(project_working_directory, "api")) - load_test_folder(os.path.join(project_working_directory, "suite")) - # load .env load_dot_env_file() + load_builtin_module() load_debugtalk_module() + load_api_folder(os.path.join(project_working_directory, "api")) + # TODO: replace suite with testcases + load_test_folder(os.path.join(project_working_directory, "suite")) def load_testcases(path): diff --git a/httprunner/runner.py b/httprunner/runner.py index 7394cb0b..7342a89a 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -45,7 +45,6 @@ class Runner(object): testcase: { "name": "testcase description", - "path": "tests/data/demo_testset_variables.yml", "variables": [], # optional "request": { "base_url": "http://127.0.0.1:5000", diff --git a/httprunner/validator.py b/httprunner/validator.py index 681a816c..739341df 100644 --- a/httprunner/validator.py +++ b/httprunner/validator.py @@ -14,7 +14,6 @@ def is_testcase(data_structure): { "config": { "name": "desc1", - "path": "", "variables": [], # optional "request": {} # optional }, diff --git a/tests/test_api.py b/tests/test_api.py index ddd377dd..c127f5d2 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -21,7 +21,6 @@ class TestHttpRunner(ApiServerUnittest): self.testcase = { 'name': 'testset description', 'config': { - 'path': 'docs/data/demo-quickstart-2.yml', 'name': 'testset description', 'request': { 'base_url': '', @@ -181,7 +180,7 @@ class TestHttpRunner(ApiServerUnittest): { "config": { "name": "test teardown hooks", - 'path': 'tests/httpbin/hooks.yml', + "path": "tests/httpbin/hooks.yml" }, "teststeps": [ { @@ -217,7 +216,7 @@ class TestHttpRunner(ApiServerUnittest): { "name": "test teardown hooks", "config": { - 'path': 'tests/httpbin/hooks.yml', + "path": "tests/httpbin/hooks.yml" }, "teststeps": [ { @@ -246,9 +245,7 @@ class TestHttpRunner(ApiServerUnittest): testcases = [ { "name": "test teardown hooks", - "config": { - 'path': 'tests/httpbin/hooks.yml', - }, + "config": {}, "teststeps": [ { "name": "test teardown hooks", diff --git a/tests/test_loader.py b/tests/test_loader.py index 64430354..699e8064 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -246,7 +246,6 @@ class TestSuiteLoader(unittest.TestCase): def test_load_test_file_testcase(self): testcase = loader._load_test_file("tests/testcases/smoketest.yml") self.assertEqual(testcase["config"]["name"], "smoketest") - self.assertEqual(testcase["config"]["path"], "tests/testcases/smoketest.yml") self.assertIn("device_sn", testcase["config"]["variables"][0]) self.assertEqual(len(testcase["teststeps"]), 8) self.assertEqual(testcase["teststeps"][0]["name"], "get token") @@ -365,8 +364,6 @@ class TestSuiteLoader(unittest.TestCase): os.getcwd(), 'tests/data/demo_testset_hardcode.json') testset_list = loader.load_testcases(path) self.assertEqual(len(testset_list), 1) - self.assertIn("path", testset_list[0]["config"]) - self.assertEqual(testset_list[0]["config"]["path"], path) self.assertEqual(len(testset_list[0]["teststeps"]), 3) testsets_list.extend(testset_list) @@ -374,8 +371,6 @@ class TestSuiteLoader(unittest.TestCase): path = 'tests/data/demo_testset_hardcode.yml' testset_list = loader.load_testcases(path) self.assertEqual(len(testset_list), 1) - self.assertIn("path", testset_list[0]["config"]) - self.assertIn(path, testset_list[0]["config"]["path"]) self.assertEqual(len(testset_list[0]["teststeps"]), 3) testsets_list.extend(testset_list) diff --git a/tests/test_runner.py b/tests/test_runner.py index bc55e979..5a5ff67f 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -80,7 +80,6 @@ class TestRunner(ApiServerUnittest): start_time = time.time() config_dict = { - "path": os.path.join(os.getcwd(), __file__), "name": "basic test with httpbin", "variables": self.debugtalk_module["variables"], "functions": self.debugtalk_module["functions"], @@ -130,7 +129,6 @@ class TestRunner(ApiServerUnittest): def test_run_testset_with_hooks_modify_request(self): config_dict = { - "path": os.path.join(os.getcwd(), __file__), "name": "basic test with httpbin", "variables": self.debugtalk_module["variables"], "functions": self.debugtalk_module["functions"], @@ -185,9 +183,7 @@ class TestRunner(ApiServerUnittest): ], "teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 2)}"] } - config_dict = { - "path": os.path.join(os.getcwd(), __file__) - } + config_dict = {} self.test_runner.init_config(config_dict, "testcase") start_time = time.time() @@ -218,9 +214,7 @@ class TestRunner(ApiServerUnittest): ], "teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 2)}"] } - config_dict = { - "path": os.path.join(os.getcwd(), __file__) - } + config_dict = {} self.test_runner.init_config(config_dict, "testcase") start_time = time.time() @@ -246,9 +240,7 @@ class TestRunner(ApiServerUnittest): testcase_file_path = os.path.join( os.getcwd(), 'tests/data/test_bugfix.yml') testcases = loader.load_file(testcase_file_path) - config_dict = { - "path": testcase_file_path - } + config_dict = {} self.test_runner.init_config(config_dict, "testcase") test = testcases[2]["test"]