Skip to content

Commit b66a122

Browse files
authored
Harden HF reachability check: verify file download, not just metadata (#134)
* Harden HF reachability check: verify file download, not just metadata model_info() can succeed while actual file downloads are blocked by proxy or firewall. Add a config.json download probe to catch this case and skip tests cleanly instead of failing with LocalEntryNotFoundError. * Harden HF reachability check: verify file download, not just metadata model_info() can succeed while actual file downloads are blocked by proxy or firewall. Add a config.json download probe to catch this case and skip tests cleanly instead of failing with LocalEntryNotFoundError.
1 parent 49becc6 commit b66a122

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

python/tests/_runner_infra/_deps.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ def _hf_hub_reachable(model_id: str = "yujiepan/qwen3-tiny-random") -> bool:
5151
Used as an opt-in gate for tests that call ``Model.from_hf(...)``. Any
5252
exception (proxy block, DNS failure, timeout, missing dep) is treated as
5353
"not reachable" so the test is skipped rather than failing.
54+
55+
Also verifies the model's config.json is downloadable — model_info()
56+
can succeed while actual file downloads are blocked by proxy/firewall.
5457
"""
5558
try:
5659
import huggingface_hub
5760

5861
huggingface_hub.HfApi().model_info(model_id, timeout=2)
62+
huggingface_hub.hf_hub_download(model_id, "config.json", timeout=5)
5963
return True
6064
except Exception:
6165
return False

python/tests/test_model_conversion/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,32 @@
1212
opt-out for Core AI-export tests where the HF impl decomposes into where-ops
1313
the Core AI runtime can't lower.
1414
15-
Also applies ``pytest.mark.flaky(reruns=5)`` to every test in this tree.
15+
Also applies ``pytest.mark.flaky(reruns=5)`` to every test in this tree
16+
and skips all tests when the HuggingFace Hub is unreachable (every test
17+
in this directory calls ``from_pretrained``).
1618
"""
1719

1820
import os
1921
from collections.abc import Iterator
2022

2123
import pytest
2224

25+
from tests._runner_infra._deps import _hf_hub_reachable
26+
2327

2428
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
2529
"""Apply flaky marker to all tests in this directory and subdirectories."""
2630
for item in items:
2731
item.add_marker(pytest.mark.flaky(reruns=5))
2832

2933

34+
@pytest.fixture(autouse=True, scope="session")
35+
def _skip_conversion_tests_if_offline() -> None:
36+
"""Skip all model conversion tests when HF Hub is unreachable."""
37+
if not _hf_hub_reachable():
38+
pytest.skip("HuggingFace Hub unreachable; skipping model conversion tests")
39+
40+
3041
@pytest.fixture(autouse=True, scope="module")
3142
def use_hf_impl() -> Iterator[None]:
3243
"""Use HuggingFace implementation for comparison tests in this module."""

0 commit comments

Comments
 (0)