Skip to content

Commit 8fe29ae

Browse files
load yaml tests from same branch as client (#3169) (#3175)
* load yaml tests from same branch as client * restore checks for failed or skipped tests (cherry picked from commit b1ad37a) Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
1 parent 3e2d322 commit 8fe29ae

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

.buildkite/run-repository.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ echo -e "\033[34;1mINFO:\033[0m TEST_SUITE ${TEST_SUITE}\033[0m"
2121
echo -e "\033[34;1mINFO:\033[0m NOX_SESSION ${NOX_SESSION}\033[0m"
2222
echo -e "\033[34;1mINFO:\033[0m PYTHON_VERSION ${PYTHON_VERSION}\033[0m"
2323
echo -e "\033[34;1mINFO:\033[0m PYTHON_CONNECTION_CLASS ${PYTHON_CONNECTION_CLASS}\033[0m"
24+
echo -e "\033[34;1mINFO:\033[0m ES_YAML_TESTS_BRANCH ${ES_YAML_TESTS_BRANCH}\033[0m"
2425

2526
echo -e "\033[1m>>>>> Build [elastic/elasticsearch-py container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
2627

@@ -42,6 +43,7 @@ docker run \
4243
--env "ELASTICSEARCH_URL=${elasticsearch_url}" \
4344
--env "TEST_SUITE=${TEST_SUITE}" \
4445
--env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \
46+
--env "ES_YAML_TESTS_BRANCH=${ES_YAML_TESTS_BRANCH}" \
4547
--env "TEST_TYPE=server" \
4648
--env "FORCE_COLOR=1" \
4749
--name elasticsearch-py \

.buildkite/run-tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export STACK_VERSION="${STACK_VERSION:=8.0.0-SNAPSHOT}"
99
export TEST_SUITE="${TEST_SUITE:=platinum}"
1010
export PYTHON_VERSION="${PYTHON_VERSION:=3.14}"
1111
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=urllib3}"
12+
export ES_YAML_TESTS_BRANCH=${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=main}
1213

1314
script_path=$(dirname $(realpath $0))
1415
source $script_path/functions/imports.sh

test_elasticsearch/test_server/test_rest_api_spec.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import json
2626
import os
2727
import re
28+
import subprocess
2829
import warnings
2930
import zipfile
3031
from typing import Tuple, Union
@@ -35,6 +36,7 @@
3536

3637
from elasticsearch import ApiError, ElasticsearchWarning, RequestError
3738
from elasticsearch._sync.client.utils import _base64_auth_header
39+
from elasticsearch._version import __versionstr__
3840
from elasticsearch.compat import string_types
3941

4042
# some params had to be changed in python, keep track of them so we can rename
@@ -499,12 +501,29 @@ def remove_implicit_resolver(cls, tag_to_remove):
499501
# Construct the HTTP and Elasticsearch client
500502
http = urllib3.PoolManager(retries=urllib3.Retry(total=10))
501503

502-
yaml_tests_url = (
503-
"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/main"
504-
)
504+
branch_candidates = []
505+
if "ES_YAML_TESTS_BRANCH" in os.environ:
506+
branch_candidates.append(os.environ["ES_YAML_TESTS_BRANCH"])
507+
git_branch = subprocess.getoutput("git branch --show-current")
508+
if git_branch not in branch_candidates:
509+
branch_candidates.append(git_branch)
510+
package_version = __versionstr__.rsplit(".", 1)[0]
511+
if package_version not in branch_candidates:
512+
branch_candidates.append(package_version)
513+
if "main" not in branch_candidates:
514+
branch_candidates.append("main")
515+
516+
response = None
517+
branch = "main"
518+
for branch in branch_candidates:
519+
yaml_tests_url = f"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/{branch}"
520+
response = http.request("GET", yaml_tests_url)
521+
if response.status != 404:
522+
break
523+
assert response is not None
505524

506525
# Download the zip and start reading YAML from the files in memory
507-
package_zip = zipfile.ZipFile(io.BytesIO(http.request("GET", yaml_tests_url).data))
526+
package_zip = zipfile.ZipFile(io.BytesIO(response.data))
508527

509528
for yaml_file in package_zip.namelist():
510529
if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file):
@@ -562,7 +581,9 @@ def remove_implicit_resolver(cls, tag_to_remove):
562581
elif pytest_test_name in SKIPPED_TESTS or pytest_param_id in SKIPPED_TESTS:
563582
pytest_param["skip"] = True
564583

565-
YAML_TEST_SPECS.append(pytest.param(pytest_param, id=pytest_param_id))
584+
YAML_TEST_SPECS.append(
585+
pytest.param(pytest_param, id=f"[{branch}]{pytest_param_id}")
586+
)
566587

567588
except Exception as e:
568589
warnings.warn(f"Could not load REST API tests: {str(e)}")

0 commit comments

Comments
 (0)