|
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,29 @@ 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 "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 |
505 | 524 |
|
506 | 525 | # 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)) |
508 | 527 |
|
509 | 528 | for yaml_file in package_zip.namelist(): |
510 | 529 | if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file): |
@@ -562,7 +581,9 @@ def remove_implicit_resolver(cls, tag_to_remove): |
562 | 581 | elif pytest_test_name in SKIPPED_TESTS or pytest_param_id in SKIPPED_TESTS: |
563 | 582 | pytest_param["skip"] = True |
564 | 583 |
|
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 | + ) |
566 | 587 |
|
567 | 588 | except Exception as e: |
568 | 589 | warnings.warn(f"Could not load REST API tests: {str(e)}") |
|
0 commit comments