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.

Restore the hub source and endpoint env between backend tests (#15131)

Daniel Hane58dd252c65d
diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.py
index 6450655e580..69b821f49ac 100644
--- a/studio/backend/tests/conftest.py
+++ b/studio/backend/tests/conftest.py
@@ -222,6 +222,29 @@ def _contain_installer_venv_root(tmp_path_factory, monkeypatch):
contain_installer_venv_root(monkeypatch, tmp_path_factory)
+# apply_hub_settings() writes these straight into os.environ, and importing the app runs it. A test
+# that left ModelScope selected put every later test on its xdist worker on that source, so the
+# auth-check probe in test_hub_token_caller_identity.py built huggingface.co URLs for a mirror.
+_HUB_SETTINGS_ENV = (
+ "UNSLOTH_STUDIO_HUB_SOURCE",
+ "HF_ENDPOINT",
+ "HF_DATASETS_SERVER",
+ "NO_PROXY",
+ "no_proxy",
+)
+
+
[email protected](autouse = True)
+def _restore_hub_settings_env():
+ saved = {name: os.environ.get(name) for name in _HUB_SETTINGS_ENV}
+ yield
+ for name, value in saved.items():
+ if value is None:
+ os.environ.pop(name, None)
+ else:
+ os.environ[name] = value
+
+
@pytest.fixture(autouse = True)
def _reset_gpu_query_cache():
# Only if already imported: importing utils.hardware would change import-order tests.
diff --git a/studio/backend/tests/test_hub_source_env_reset_between_tests.py b/studio/backend/tests/test_hub_source_env_reset_between_tests.py
new file mode 100644
index 00000000000..280fc2773ea
--- /dev/null
+++ b/studio/backend/tests/test_hub_source_env_reset_between_tests.py
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+"""A hub source one test applies does not decide the next test's endpoint.
+
+``apply_hub_settings()`` writes ``UNSLOTH_STUDIO_HUB_SOURCE`` and the endpoints straight into
+``os.environ``. A test that left ModelScope selected made ``_probe_endpoint()`` answer
+huggingface.co for every later test on the xdist worker, and
+``test_the_probe_url_is_built_safely`` then failed for a mirror it had set itself. The two tests
+below run in order on one worker: the first writes the source the way the settings code does, the
+second fails unless conftest put it back in between.
+"""
+
+from __future__ import annotations
+
+import os
+
+import pytest
+
+from utils import hub_settings
+
+pytestmark = pytest.mark.xdist_group("hub_source_env_reset_between_tests")
+
+
+def test_a_test_leaves_modelscope_selected():
+ # Assigned, not monkeypatched: apply_hub_settings() writes it the same way.
+ os.environ[hub_settings.SOURCE_ENV] = hub_settings.MODELSCOPE
+ assert hub_settings.active_source() == hub_settings.MODELSCOPE
+
+
+def test_the_next_test_starts_on_the_source_it_inherited():
+ assert os.environ.get(hub_settings.SOURCE_ENV) != hub_settings.MODELSCOPE
+ assert hub_settings.active_source() == hub_settings.HUGGINGFACE