Skip to content

Commit 99dd070

Browse files
load yaml tests from same branch as client
1 parent 7314645 commit 99dd070

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

test_elasticsearch/test_server/test_rest_api_spec.py

Lines changed: 11 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
@@ -499,12 +500,17 @@ def remove_implicit_resolver(cls, tag_to_remove):
499500
# Construct the HTTP and Elasticsearch client
500501
http = urllib3.PoolManager(retries=urllib3.Retry(total=10))
501502

502-
yaml_tests_url = (
503-
"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/main"
504-
)
503+
branch = subprocess.getoutput("git branch --show-current")
504+
yaml_tests_url = f"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/{branch}"
505+
response = http.request("GET", yaml_tests_url)
506+
if response.status == 404 and branch != "main":
507+
# this branch does not exist in the yaml tests repo, so we use main instead
508+
branch = "main"
509+
yaml_tests_url = f"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/{branch}"
510+
response = http.request("GET", yaml_tests_url)
505511

506512
# 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))
513+
package_zip = zipfile.ZipFile(io.BytesIO(response.data))
508514

509515
for yaml_file in package_zip.namelist():
510516
if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file):
@@ -549,7 +555,7 @@ def remove_implicit_resolver(cls, tag_to_remove):
549555
for prefix in ("rest-api-spec/", "test/", "free/", "platinum/"):
550556
if pytest_test_name.startswith(prefix):
551557
pytest_test_name = pytest_test_name[len(prefix) :]
552-
pytest_param_id = "%s[%d]" % (pytest_test_name, test_number)
558+
pytest_param_id = "[%s]%s[%d]" % (branch, pytest_test_name, test_number)
553559

554560
pytest_param = {
555561
"setup": setup_steps,

0 commit comments

Comments
 (0)