|
| 1 | +--- a/tests/utils.py |
| 2 | ++++ b/tests/utils.py |
| 3 | +@@ -3,7 +3,11 @@ |
| 4 | + |
| 5 | + import pytest |
| 6 | + |
| 7 | +-from huggingface_hub import hf_hub_download |
| 8 | ++try: |
| 9 | ++ from huggingface_hub import hf_hub_download as _hf_hub_download |
| 10 | ++ _HF_AVAILABLE = True |
| 11 | ++except ImportError: |
| 12 | ++ _HF_AVAILABLE = False |
| 13 | + |
| 14 | + |
| 15 | + DATA_PATH = os.path.join("tests", "data") |
| 16 | +@@ -11,8 +15,10 @@ |
| 17 | + |
| 18 | + |
| 19 | + def download(filename): |
| 20 | ++ if not _HF_AVAILABLE: |
| 21 | ++ pytest.skip("huggingface_hub is not installed") |
| 22 | + # huggingface_hub handles auth (HF_TOKEN), retry/backoff and ETag-based caching. |
| 23 | +- return hf_hub_download(repo_id=HF_TEST_REPO, filename=filename, repo_type="dataset") |
| 24 | ++ return _hf_hub_download(repo_id=HF_TEST_REPO, filename=filename, repo_type="dataset") |
| 25 | + |
| 26 | + |
| 27 | + @pytest.fixture(scope="session") |
| 28 | +--- a/tests/test_serialization.py |
| 29 | ++++ b/tests/test_serialization.py |
| 30 | +@@ -4,7 +4,10 @@ |
| 31 | + import unittest |
| 32 | + |
| 33 | + import tqdm |
| 34 | +-from huggingface_hub import hf_hub_download |
| 35 | ++try: |
| 36 | ++ from huggingface_hub import hf_hub_download |
| 37 | ++except ImportError: |
| 38 | ++ hf_hub_download = None |
| 39 | + from tokenizers import Tokenizer |
| 40 | + from tokenizers.models import BPE, Unigram |
| 41 | + |
| 42 | +--- a/tests/documentation/test_tutorial_train_from_iterators.py |
| 43 | ++++ b/tests/documentation/test_tutorial_train_from_iterators.py |
| 44 | +@@ -2,8 +2,11 @@ |
| 45 | + import gzip |
| 46 | + import os |
| 47 | + |
| 48 | +-import datasets # type: ignore[import-not-found] |
| 49 | + import pytest |
| 50 | ++try: |
| 51 | ++ import datasets # type: ignore[import-not-found] |
| 52 | ++except ImportError: |
| 53 | ++ pytest.skip("datasets is not installed", allow_module_level=True) |
| 54 | + |
| 55 | + from ..utils import data_dir, train_files |
| 56 | + |
0 commit comments