From 92474887d6cb352bc28f63251ad7f00f6190ec9a Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 28 Feb 2019 15:22:08 +0800 Subject: [PATCH] bugfix verify priority: nested testcase config > testcase config --- httprunner/parser.py | 6 +++--- tests/test_parser.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/httprunner/parser.py b/httprunner/parser.py index 94d7d822..ca195529 100644 --- a/httprunner/parser.py +++ b/httprunner/parser.py @@ -731,9 +731,6 @@ def _extend_with_testcase(test_dict, testcase_def_dict): if not testcase_def_dict["config"].get("base_url"): testcase_def_dict["config"]["base_url"] = test_base_url - test_verify = test_dict.pop("verify", True) - testcase_def_dict["config"].setdefault("verify", test_verify) - # override name test_name = test_dict.pop("name") or testcase_def_dict["config"].pop("name") or "Undefined name" @@ -845,6 +842,9 @@ def __parse_testcase_tests(tests, config, project_mapping): testcase_def = test_dict.pop("testcase_def") _extend_with_testcase(test_dict, testcase_def) + # verify priority: nested testcase config > testcase config + test_dict["config"].setdefault("verify", config_verify) + # 3, testcase_def config => testcase_def test_dict _parse_testcase(test_dict, project_mapping) diff --git a/tests/test_parser.py b/tests/test_parser.py index 8f97ea30..c0deb228 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -803,6 +803,41 @@ class TestParser(unittest.TestCase): test_dict = parsed_tests_mapping["testcases"][0]["teststeps"][0] self.assertEqual(test_dict["request"]["verify"], False) + def test_parse_tests_verify_nested_testcase_unset(self): + tests_mapping = { + 'testcases': [ + { + 'config': { + 'name': 'inquiry price', + 'verify': False + }, + 'teststeps': [ + { + 'name': 'login system', + 'testcase': 'testcases/deps/login.yml', + 'testcase_def': { + 'config': { + 'name': 'login system' + }, + 'teststeps': [ + { + 'name': '/', + 'request': { + 'method': 'GET', + 'url': 'https://httpbin.org/' + } + } + ] + } + } + ] + } + ] + } + parsed_tests_mapping = parser.parse_tests(tests_mapping) + test_dict = parsed_tests_mapping["testcases"][0]["teststeps"][0] + self.assertEqual(test_dict["teststeps"][0]["request"]["verify"], False) + def test_parse_environ(self): os.environ["PROJECT_KEY"] = "ABCDEFGH" content = {