Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Support optional imports in unit tests (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
izellevy authored Feb 14, 2024
1 parent c9ce812 commit 181762c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion tests/unit/tokenizer/test_cohere_hf_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ class TestCohereHFTokenizer(BaseTestTokenizer):
@staticmethod
@pytest.fixture(scope="class")
def tokenizer():
return CohereHFTokenizer()
try:
tokenizer = CohereHFTokenizer()
except ImportError:
pytest.skip(
"`cohere` extra not installed. Skipping CohereHFTokenizer unit "
"tests"
)
return tokenizer

@staticmethod
@pytest.fixture
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/tokenizer/test_llama_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ class TestLlamaTokenizer(BaseTestTokenizer):
@staticmethod
@pytest.fixture(scope="class")
def tokenizer():
return LlamaTokenizer(model_name="hf-internal-testing/llama-tokenizer")
try:
tokenizer = LlamaTokenizer(model_name="hf-internal-testing/llama-tokenizer")
except ImportError:
pytest.skip(
"`transformers` extra not installed. Skipping LLamaTokenizer unit "
"tests"
)
return tokenizer

@staticmethod
@pytest.fixture
Expand Down

0 comments on commit 181762c

Please sign in to comment.