From 73dcded823d0889e80f6b1bc721a8df7d8070c1a Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 24 Feb 2019 18:48:03 +0800 Subject: [PATCH] bugfix verify priority: teststep > config --- httprunner/parser.py | 11 +++++-- tests/test_parser.py | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/httprunner/parser.py b/httprunner/parser.py index cd033299..94d7d822 100644 --- a/httprunner/parser.py +++ b/httprunner/parser.py @@ -794,9 +794,12 @@ def __parse_testcase_tests(tests, config, project_mapping): variables priority: testcase config > testcase test > testcase_def config > testcase_def test > api - base_url/verify priority: + base_url priority: testcase test > testcase config > testsuite test > testsuite config > api + verify priority: + testcase teststep (api) > testcase config > testsuite config + Args: tests (list): config (dict): @@ -814,8 +817,6 @@ def __parse_testcase_tests(tests, config, project_mapping): if (not test_dict.get("base_url")) and config_base_url: test_dict["base_url"] = config_base_url - test_dict.setdefault("verify", config_verify) - # 1, testcase config => testcase tests # override test_dict variables test_dict["variables"] = utils.extend_variables( @@ -875,6 +876,10 @@ def __parse_testcase_tests(tests, config, project_mapping): request_url ) + # verify priority: testcase teststep > testcase config + if "request" in test_dict and "verify" not in test_dict["request"]: + test_dict["request"]["verify"] = config_verify + def _parse_testcase(testcase, project_mapping): """ parse testcase diff --git a/tests/test_parser.py b/tests/test_parser.py index 153086fa..8f97ea30 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -732,6 +732,77 @@ class TestParser(unittest.TestCase): self.assertEqual(test_dict["request"]["url"], "https://debugtalk.com/api1") self.assertEqual(test_dict["request"]["verify"], True) + def test_parse_tests_verify_config_set(self): + """ verify priority: test_dict > config + """ + tests_mapping = { + 'testcases': [ + { + "config": { + 'name': 'bugfix verify', + "base_url": "https://httpbin.org/", + "verify": False + }, + "teststeps": [ + { + 'name': 'testcase1', + 'request': {'url': '/headers', 'method': 'GET'} + } + ] + } + ] + } + parsed_tests_mapping = parser.parse_tests(tests_mapping) + test_dict = parsed_tests_mapping["testcases"][0]["teststeps"][0] + self.assertEqual(test_dict["request"]["verify"], False) + + def test_parse_tests_verify_config_unset(self): + """ verify priority: test_dict > config + """ + tests_mapping = { + 'testcases': [ + { + "config": { + 'name': 'bugfix verify', + "base_url": "https://httpbin.org/", + }, + "teststeps": [ + { + 'name': 'testcase1', + 'request': {'url': '/headers', 'method': 'GET'} + } + ] + } + ] + } + parsed_tests_mapping = parser.parse_tests(tests_mapping) + test_dict = parsed_tests_mapping["testcases"][0]["teststeps"][0] + self.assertEqual(test_dict["request"]["verify"], True) + + def test_parse_tests_verify_step_set_false(self): + """ verify priority: test_dict > config + """ + tests_mapping = { + 'testcases': [ + { + "config": { + 'name': 'bugfix verify', + "base_url": "https://httpbin.org/", + "verify": True + }, + "teststeps": [ + { + 'name': 'testcase1', + 'request': {'url': '/headers', 'method': 'GET', "verify": False} + } + ] + } + ] + } + parsed_tests_mapping = parser.parse_tests(tests_mapping) + test_dict = parsed_tests_mapping["testcases"][0]["teststeps"][0] + self.assertEqual(test_dict["request"]["verify"], False) + def test_parse_environ(self): os.environ["PROJECT_KEY"] = "ABCDEFGH" content = {