Skip to content

Commit

Permalink
skip HF integrations tests if running from fork (#7517)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Apr 9, 2024
1 parent d9c861e commit 39be515
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -320,6 +321,10 @@ def test_run_custom_batch_size(self, mock_check_valid_model):

@pytest.mark.flaky(reruns=5, reruns_delay=5)
@pytest.mark.integration
@pytest.mark.skipif(
not os.environ.get("HF_API_TOKEN", None),
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
)
def test_live_run_serverless(self):
docs = [
Document(content="I love cheese", meta={"topic": "Cuisine"}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -161,6 +162,10 @@ def test_run(self, mock_check_valid_model):

@pytest.mark.flaky(reruns=5, reruns_delay=5)
@pytest.mark.integration
@pytest.mark.skipif(
not os.environ.get("HF_API_TOKEN", None),
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
)
def test_live_run_serverless(self):
embedder = HuggingFaceAPITextEmbedder(
api_type=HFEmbeddingAPIType.SERVERLESS_INFERENCE_API,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import MagicMock, patch

import numpy as np
Expand Down Expand Up @@ -305,6 +306,10 @@ def test_run(self, mock_check_valid_model):

@pytest.mark.flaky(reruns=5, reruns_delay=5)
@pytest.mark.integration
@pytest.mark.skipif(
not os.environ.get("HF_API_TOKEN", None),
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
)
def test_run_inference_api_endpoint(self):
docs = [
Document(content="I love cheese", meta={"topic": "Cuisine"}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import MagicMock, patch

import numpy as np
Expand Down Expand Up @@ -177,6 +178,10 @@ def test_run(self, mock_check_valid_model):

@pytest.mark.flaky(reruns=5, reruns_delay=5)
@pytest.mark.integration
@pytest.mark.skipif(
not os.environ.get("HF_API_TOKEN", None),
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
)
def test_run_inference_api_endpoint(self):
embedder = HuggingFaceTEITextEmbedder(model="sentence-transformers/all-MiniLM-L6-v2")
result = embedder.run(text="The food was delicious")
Expand Down
6 changes: 6 additions & 0 deletions test/components/generators/chat/test_hugging_face_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import MagicMock, Mock, patch

import pytest
Expand Down Expand Up @@ -239,7 +240,12 @@ def mock_iter(self):
assert len(response["replies"]) > 0
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]

@pytest.mark.flaky(reruns=5, reruns_delay=5)
@pytest.mark.integration
@pytest.mark.skipif(
not os.environ.get("HF_API_TOKEN", None),
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
)
def test_run_serverless(self):
generator = HuggingFaceAPIChatGenerator(
api_type=HFGenerationAPIType.SERVERLESS_INFERENCE_API,
Expand Down
6 changes: 6 additions & 0 deletions test/components/generators/test_hugging_face_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import MagicMock, Mock, patch

import pytest
Expand Down Expand Up @@ -272,7 +273,12 @@ def mock_iter(self):
assert len(response["meta"]) > 0
assert [isinstance(meta, dict) for meta in response["meta"]]

@pytest.mark.flaky(reruns=5, reruns_delay=5)
@pytest.mark.integration
@pytest.mark.skipif(
not os.environ.get("HF_API_TOKEN", None),
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
)
def test_run_serverless(self):
generator = HuggingFaceAPIGenerator(
api_type=HFGenerationAPIType.SERVERLESS_INFERENCE_API,
Expand Down

0 comments on commit 39be515

Please sign in to comment.