|
25 | 25 | import json |
26 | 26 | import os |
27 | 27 | import re |
| 28 | +import subprocess |
28 | 29 | import warnings |
29 | 30 | import zipfile |
30 | 31 | from typing import Tuple, Union |
|
35 | 36 |
|
36 | 37 | from elasticsearch import ApiError, ElasticsearchWarning, RequestError |
37 | 38 | from elasticsearch._sync.client.utils import _base64_auth_header |
| 39 | +from elasticsearch._version import __versionstr__ |
38 | 40 | from elasticsearch.compat import string_types |
39 | 41 |
|
40 | 42 | # some params had to be changed in python, keep track of them so we can rename |
@@ -499,12 +501,28 @@ def remove_implicit_resolver(cls, tag_to_remove): |
499 | 501 | # Construct the HTTP and Elasticsearch client |
500 | 502 | http = urllib3.PoolManager(retries=urllib3.Retry(total=10)) |
501 | 503 |
|
502 | | - yaml_tests_url = ( |
503 | | - "https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/main" |
504 | | - ) |
| 504 | + branch_candidates = [] |
| 505 | + if "YAML_TESTS_BRANCH" in os.environ: |
| 506 | + branch_candidates.append(os.environ["YAML_TESTS_BRANCH"] or "main") |
| 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 | + for branch in branch_candidates: |
| 518 | + yaml_tests_url = f"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/{branch}" |
| 519 | + response = http.request("GET", yaml_tests_url) |
| 520 | + if response.status != 404: |
| 521 | + break |
| 522 | + assert response is not None |
505 | 523 |
|
506 | 524 | # 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)) |
| 525 | + package_zip = zipfile.ZipFile(io.BytesIO(response.data)) |
508 | 526 |
|
509 | 527 | for yaml_file in package_zip.namelist(): |
510 | 528 | if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file): |
@@ -549,7 +567,7 @@ def remove_implicit_resolver(cls, tag_to_remove): |
549 | 567 | for prefix in ("rest-api-spec/", "test/", "free/", "platinum/"): |
550 | 568 | if pytest_test_name.startswith(prefix): |
551 | 569 | pytest_test_name = pytest_test_name[len(prefix) :] |
552 | | - pytest_param_id = "%s[%d]" % (pytest_test_name, test_number) |
| 570 | + pytest_param_id = "[%s]%s[%d]" % (branch, pytest_test_name, test_number) |
553 | 571 |
|
554 | 572 | pytest_param = { |
555 | 573 | "setup": setup_steps, |
|
0 commit comments