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.

tests: make the torchcodec provenance and mirror repair tests hermetic (#12850)

Daniel Handc10bb54312f
diff --git a/tests/python/test_torchcodec_torch_compat.py b/tests/python/test_torchcodec_torch_compat.py
index 892873506da..2448c7fbd70 100644
--- a/tests/python/test_torchcodec_torch_compat.py
+++ b/tests/python/test_torchcodec_torch_compat.py
@@ -1069,6 +1069,13 @@ def test_a_mismatched_accelerator_build_is_named_when_the_codec_cannot_load(monk
fixes = _load_import_fixes_module()
_stub_torch(monkeypatch, "2.11.0+cu128")
+ # Metadata is read first; report none so the stub answers, installed codec or not.
+ import importlib.metadata
+
+ def _no_metadata(name):
+ raise importlib.metadata.PackageNotFoundError(name)
+
+ monkeypatch.setattr(importlib.metadata, "version", _no_metadata)
codec = types.ModuleType("torchcodec")
codec.__version__ = "0.11.0" # untagged: PyPI's default build
monkeypatch.setitem(sys.modules, "torchcodec", codec)
@@ -1370,8 +1377,8 @@ def test_the_provenance_hint_reads_a_codec_it_cannot_import(monkeypatch):
fixes = _load_import_fixes_module()
_stub_torch(monkeypatch, "2.11.0+cu128")
- # No importable torchcodec at all, which is what a failed initialisation leaves behind.
- monkeypatch.delitem(sys.modules, "torchcodec", raising = False)
+ # None blocks the import even with a codec installed, as a failed initialisation does.
+ monkeypatch.setitem(sys.modules, "torchcodec", None)
def _version(name):
if name == "torchcodec":
@@ -1508,6 +1515,17 @@ def test_a_query_authenticated_mirror_is_not_pinned_at_all(monkeypatch):
def test_query_authenticated_mirror_repairs_decline_instead_of_falling_back(monkeypatch):
"""The eight repair/flavor paths must neither mangle the token nor leave the mirror."""
+ # Hidden CUDA returns before the mirror is read; index/backend pins pick another path.
+ for name in (
+ "CUDA_VISIBLE_DEVICES",
+ "UNSLOTH_TORCH_INDEX_URL",
+ "UNSLOTH_TORCH_INDEX_FAMILY",
+ "UNSLOTH_TORCH_INSTALL_INDEX_URL",
+ "UNSLOTH_TORCH_BACKEND",
+ "UNSLOTH_ROCM_TORCH_INSTALLED",
+ "UNSLOTH_FORCE_ROCM_TORCH",
+ ):
+ monkeypatch.delenv(name, raising = False)
monkeypatch.setenv("UNSLOTH_PYTORCH_MIRROR", "https://mirror.example/whl?token=abc")
mod = _reload_install_python_stack()