From a4ce29e656897c93db490d4cb47ee64343030870 Mon Sep 17 00:00:00 2001 From: httprunner Date: Tue, 27 Nov 2018 23:58:54 +0800 Subject: [PATCH] bugfix: parse test variables with config variables --- httprunner/parser.py | 12 ++++++++++++ tests/test_parser.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/httprunner/parser.py b/httprunner/parser.py index 7853778f..d3fb7a7e 100644 --- a/httprunner/parser.py +++ b/httprunner/parser.py @@ -768,6 +768,12 @@ def __parse_tests(tests, config, project_mapping): test_dict.pop("variables", {}), config_variables ) + # parse test variables with config variables + test_dict["variables"] = parse_data( + test_dict["variables"], + test_dict["variables"], + functions + ) # parse test_dict name try: @@ -797,6 +803,12 @@ def __parse_tests(tests, config, project_mapping): test_dict.pop("variables", {}), config_variables ) + # parse test variables with config variables + test_dict["variables"] = parse_data( + test_dict["variables"], + test_dict["variables"], + functions + ) # parse test_dict name try: diff --git a/tests/test_parser.py b/tests/test_parser.py index 5bf8353d..e0aa0bbf 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -452,6 +452,34 @@ class TestParser(unittest.TestCase): # self.assertEqual(len(parsed_testcases), 2 * 2) self.assertEqual(parsed_testcases[0]["config"]["name"], '1230') + def test_parse_tests_fix_override_variables(self): + tests_mapping = { + 'testcases': [ + { + 'config': { + 'name': '', + 'variables': [ + {"password": "123456"}, + {"creator": "user_test_001"} + ] + }, + 'tests': [ + { + 'name': 'testcase1', + "variables": [ + {"creator": "user_test_002"}, + {"username": "$creator"} + ], + 'request': {'url': '/api1', 'method': 'GET'} + } + ] + } + ] + } + parser.parse_tests(tests_mapping) + test_dict1_variables = tests_mapping["testcases"][0]["tests"][0]["variables"] + self.assertEqual(test_dict1_variables["username"], "user_test_001") + def test_parse_environ(self): os.environ["PROJECT_KEY"] = "ABCDEFGH" content = {