Skip to content

Commit 74d105a

Browse files
load yaml tests from same branch as client (#3169) (#3173)
* 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 2804b0a commit 74d105a

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.13}"
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 -s $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
@@ -24,6 +24,7 @@
2424
import json
2525
import os
2626
import re
27+
import subprocess
2728
import warnings
2829
import zipfile
2930
from typing import Tuple, Union
@@ -34,6 +35,7 @@
3435

3536
from elasticsearch import ApiError, ElasticsearchWarning, RequestError
3637
from elasticsearch._sync.client.utils import _base64_auth_header
38+
from elasticsearch._version import __versionstr__
3739
from elasticsearch.compat import string_types
3840

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

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

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

507526
for yaml_file in package_zip.namelist():
508527
if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file):
@@ -560,7 +579,9 @@ def remove_implicit_resolver(cls, tag_to_remove):
560579
elif pytest_test_name in SKIPPED_TESTS or pytest_param_id in SKIPPED_TESTS:
561580
pytest_param["skip"] = True
562581

563-
YAML_TEST_SPECS.append(pytest.param(pytest_param, id=pytest_param_id))
582+
YAML_TEST_SPECS.append(
583+
pytest.param(pytest_param, id=f"[{branch}]{pytest_param_id}")
584+
)
564585

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

0 commit comments

Comments
 (0)