From b6e460bb5d184c250bc82202863f3c71e3a5bae3 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 21 Nov 2025 12:46:37 +0000 Subject: [PATCH] Add global variable support to YAML test expression parser --- .../test_server/test_rest_api_spec.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test_elasticsearch/test_server/test_rest_api_spec.py b/test_elasticsearch/test_server/test_rest_api_spec.py index ea542efba..d647f942f 100644 --- a/test_elasticsearch/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_server/test_rest_api_spec.py @@ -411,16 +411,21 @@ def _resolve(self, value): return value def _lookup(self, path): - # fetch the possibly nested value from last_response - value = self.last_response if path == "$body": - return value + return self.last_response + if path.startswith("$"): + value = None + else: + value = self.last_response path = path.replace(r"\.", "\1") for step in path.split("."): if not step: continue # We check body again to handle E.g. '$body.$backing_index.data_stream' - if step.startswith("$body"): + if step == "$body": + assert value is None + # fetch the possibly nested value from last_response + value = self.last_response continue step = step.replace("\1", ".") step = self._resolve(step) @@ -432,11 +437,15 @@ def _lookup(self, path): step = int(step) assert isinstance(value, list) assert len(value) > step + value = value[step] elif step == "_arbitrary_key_": return list(value.keys())[0] - else: + elif isinstance(step, string_types) and isinstance(value, dict): assert step in value - value = value[step] + value = value[step] + else: + assert value is None + value = step return value def _feature_enabled(self, name):