Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Stop test_dataset_cache_safe leaking the Hub no-symlink switch into later tests (#12973)

Daniel Han660bcbad91f0
diff --git a/studio/backend/tests/test_dataset_cache_safe.py b/studio/backend/tests/test_dataset_cache_safe.py
index 3af6d297c26..99b08681442 100644
--- a/studio/backend/tests/test_dataset_cache_safe.py
+++ b/studio/backend/tests/test_dataset_cache_safe.py
@@ -32,6 +32,36 @@ def _install_fake_datasets(monkeypatch, load_dataset):
monkeypatch.setattr("loggers.config.quiet_third_party_progress_bars", lambda: None)
+_UNSET = object()
+
+
[email protected](autouse = True)
+def _restore_process_symlink_state():
+ """_disable_hf_symlinks_for_process changes the env var and Hub's live flag for the whole worker.
+
+ A test that calls it without patching both first left HF_HUB_DISABLE_SYMLINKS=1 and
+ constants.HF_HUB_DISABLE_SYMLINKS=True behind, so every later test in that xdist worker cached
+ regular files instead of symlinks (test_gguf_header_delta's blob layout failed on CI that way).
+ `monkeypatch.delenv(..., raising = False)` on an unset variable records nothing to undo, so
+ restore all three pieces here whatever the test did.
+ """
+ from huggingface_hub import constants, file_download
+
+ env = os.environ.get("HF_HUB_DISABLE_SYMLINKS", _UNSET)
+ flag = vars(constants).get("HF_HUB_DISABLE_SYMLINKS", _UNSET)
+ support = file_download._are_symlinks_supported_in_dir
+ yield
+ if env is _UNSET:
+ os.environ.pop("HF_HUB_DISABLE_SYMLINKS", None)
+ else:
+ os.environ["HF_HUB_DISABLE_SYMLINKS"] = env
+ if flag is _UNSET:
+ vars(constants).pop("HF_HUB_DISABLE_SYMLINKS", None)
+ else:
+ constants.HF_HUB_DISABLE_SYMLINKS = flag
+ file_download._are_symlinks_supported_in_dir = support
+
+
def _isolate_hub_symlink_state(monkeypatch):
"""Keep _disable_hf_symlinks_for_process from leaking into other tests."""
from huggingface_hub import constants, file_download
diff --git a/studio/backend/tests/test_gguf_header_delta.py b/studio/backend/tests/test_gguf_header_delta.py
index 5beb8cf5603..36b87711cf3 100644
--- a/studio/backend/tests/test_gguf_header_delta.py
+++ b/studio/backend/tests/test_gguf_header_delta.py
@@ -106,6 +106,12 @@ def cache_with_old(
@pytest.fixture(autouse = True)
def _small_ranges(monkeypatch, tmp_path):
monkeypatch.delenv(delta.DELTA_ENV, raising = False)
+ # The blob-layout tests build a symlinked cache themselves, so Hub must agree symlinks work here,
+ # whatever an earlier test in this worker did to its process-wide symlink switch.
+ from huggingface_hub import constants, file_download
+
+ monkeypatch.setattr(constants, "HF_HUB_DISABLE_SYMLINKS", False, raising = False)
+ monkeypatch.setattr(file_download, "_are_symlinks_supported_in_dir", {})
monkeypatch.setattr(delta, "_FIRST_RANGE", 64)
monkeypatch.setattr(delta, "_HEADER_SLACK", 64)
memo = tmp_path / "refused.json"