|
24 | 24 | import json |
25 | 25 | import os |
26 | 26 | import re |
| 27 | +import subprocess |
27 | 28 | import warnings |
28 | 29 | import zipfile |
29 | 30 | from typing import Tuple, Union |
|
34 | 35 |
|
35 | 36 | from elasticsearch import ApiError, ElasticsearchWarning, RequestError |
36 | 37 | from elasticsearch._sync.client.utils import _base64_auth_header |
| 38 | +from elasticsearch._version import __versionstr__ |
37 | 39 | from elasticsearch.compat import string_types |
38 | 40 |
|
39 | 41 | # 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): |
497 | 499 | # Construct the HTTP and Elasticsearch client |
498 | 500 | http = urllib3.PoolManager(retries=urllib3.Retry(total=10)) |
499 | 501 |
|
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 |
503 | 522 |
|
504 | 523 | # 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)) |
506 | 525 |
|
507 | 526 | for yaml_file in package_zip.namelist(): |
508 | 527 | if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file): |
@@ -560,7 +579,9 @@ def remove_implicit_resolver(cls, tag_to_remove): |
560 | 579 | elif pytest_test_name in SKIPPED_TESTS or pytest_param_id in SKIPPED_TESTS: |
561 | 580 | pytest_param["skip"] = True |
562 | 581 |
|
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 | + ) |
564 | 585 |
|
565 | 586 | except Exception as e: |
566 | 587 | warnings.warn(f"Could not load REST API tests: {str(e)}") |
|
0 commit comments