huggingface.py 525 B

123456789101112131415161718192021
  1. import os
  2. import pytest
  3. from _pytest.monkeypatch import MonkeyPatch
  4. from huggingface_hub import InferenceClient
  5. from tests.integration_tests.model_runtime.__mock.huggingface_chat import MockHuggingfaceChatClass
  6. MOCK = os.getenv("MOCK_SWITCH", "false").lower() == "true"
  7. @pytest.fixture
  8. def setup_huggingface_mock(request, monkeypatch: MonkeyPatch):
  9. if MOCK:
  10. monkeypatch.setattr(InferenceClient, "text_generation", MockHuggingfaceChatClass.text_generation)
  11. yield
  12. if MOCK:
  13. monkeypatch.undo()