From 4077db8b578fb2ad7da16349feeb2a348d745dfd Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov Date: Mon, 7 Sep 2026 11:48:37 -0700 Subject: [PATCH] Stub huggingface_hub in the allow-patterns test instead of importing it The test monkeypatched huggingface_hub.snapshot_download by string, which imports the real module. huggingface-hub rides the classify extra, not the dev sync, so the CI matrix failed with ModuleNotFoundError on every platform while the shared checkout venv hid the gap. Insert a stub into sys.modules instead: the seam under test is classify's request, not the hub client. --- tests/test_classify.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_classify.py b/tests/test_classify.py index 265d1ad..772af40 100644 --- a/tests/test_classify.py +++ b/tests/test_classify.py @@ -63,19 +63,21 @@ def test_runtime_requests_the_exported_allow_patterns(monkeypatch: pytest.Monkey """ from remove_ai_watermarks.classify import _WEIGHT_FILES, _weights_dir - captured: dict[str, object] = {} + captured: dict[str, object] = [] def fake_snapshot_download(**kwargs: object) -> str: - captured.update(kwargs) + captured.append(kwargs) return "/cached/snapshot" - monkeypatch.setattr("huggingface_hub.snapshot_download", fake_snapshot_download) + # huggingface_hub ships with the classify extra, not with the dev sync, + # so stub the module instead of importing it. + monkeypatch.setitem(sys.modules, "huggingface_hub", SimpleNamespace(snapshot_download=fake_snapshot_download)) monkeypatch.delenv("RAIW_CLASSIFY_WEIGHTS", raising=False) assert _weights_dir() == Path("/cached/snapshot") - assert captured["repo_id"] == WEIGHTS_REPO - assert captured["revision"] == WEIGHTS_REVISION - assert captured["allow_patterns"] == list(WEIGHTS_ALLOW_PATTERNS) + assert captured[0]["repo_id"] == WEIGHTS_REPO + assert captured[0]["revision"] == WEIGHTS_REVISION + assert captured[0]["allow_patterns"] == list(WEIGHTS_ALLOW_PATTERNS) assert set(_WEIGHT_FILES) <= set(WEIGHTS_ALLOW_PATTERNS)